0

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 は RUNWAY-TITLE です

4

4 に答える 4

0

どちらの div が中央に配置されていないか (どちらを指定しないか)。設定

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

それはトリックを行う必要があります。

于 2013-09-21T06:04:13.263 に答える
0

内部 div に高さと幅を割り当てるだけです。内部 div の margin-left と margin-right を「auto」に設定します。

于 2013-09-21T06:04:41.173 に答える
0

私があなたのために作ったこのサンプルを見てください。うまくいくと思います

デモフィドル

#runway-category {
text-align:center;
border: 1px solid black;
}
.runway-category-posts {
margin: 2px;
}
.photo {
margin:0px 25px 0px 25px;
border: 1px solid black;
}
于 2013-09-21T06:17:20.903 に答える
0

" div style="background:green;width:200;height:200;position:absolute;" div style="background:red;width:100;height:100;margin:auto;position:absolute;top:0 を使用;下:0;左:0;右:0;"

/div /div"

于 2013-09-21T06:23:05.893 に答える