2013-09-21 143 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“