2013-09-21 145 views
0

我想將div居中在另一個div中。Div在另一個div中居中

這是我的HTML

<div id="runway-category"> 
    <a href="<?php the_permalink() ?>" class="runway-category-posts"> 
     <div class="photo"><?php custom_get_post_attachments(get_the_ID(), $__width, $__height, get_the_title()); ?><div class="runway-title"><?php the_title(); ?></div></div> 
    </a>   
</div> 

這是CSS

.runway-category-posts{width:298px;height:500px;margin: 0 9px 18px 9px;float:left;display:block;} 
.runway-title{text-align:center;font-family:tall_film;color:#FFF;font-size:20px;} 

請告訴我,我應該添加到CSS做是正確的?

編輯 - 這應該在PHOTO DIV居中的DIV是跑道TITLE

+1

嘗試'margin-left:auto; margin-right:auto;'特別是'div' –

+0

http://www.jakpsatweb.cz/css/css-vertical-center-solution.html – biziclop

回答

0

取其格沒有被居中(你不指定)。設置

margin-left: auto; 
margin-right: auto; 

應該做的伎倆。

+0

我需要將它居中verticaly –

+0

快速谷歌搜索導致:http ://blog.themeforest.net/tutorials/vertical-centering-with-css/ –

0

只是將innerdiv的內部div.put margin-left和margin-right分配給'auto'的高度和寬度。

+0

我需要將它居中放置。 –

0

看一看這個樣本我爲你做的,我認爲它會做的伎倆

Demo Fiddle

#runway-category { 
text-align:center; 
border: 1px solid black; 
} 
.runway-category-posts { 
margin: 2px; 
} 
.photo { 
margin:0px 25px 0px 25px; 
border: 1px solid black; 
} 
0

使用 「 DIV的風格=」 背景:綠色;寬度:200;高度: 200; position:absolute;「 div style =」background:red; width:100; height:100; margin:auto; position:absolute; top:0; bottom:0; left:0; right:0;「

/div /div「