CSS中心内容div [英] CSS center content inside div
问题描述
我需要将html内容置于div class =partners(顶部div和2张图片)中心。从下面的图片可以看到(它是左移而不是div的中心):
I need to center html content inside a div class="partners" (top div with 2 images). As you can see from the image below (it floats left instead of center of the div):
这是我的html代码:
This is my html code:
<div id="partners">
<div class="wrap clearfix">
<h2>Partnertnerzy serwisu:</h2>
<ul>
<li><a href="http://www.dilbert.com/"><img width="56" height="16" alt="Parnter bar wika" src="/as/partners/wika.png"></a></li>
<li><a href="http://www.youtube.com><img width="65" height="15" alt="Parnter bar siemens" src="/as/partners/siemens.png"></a></li>
</ul>
<a class="linkClose" href="/firmy?clbp=1">Zamknij </a>
</div>
</div>
$ b b
图片:
>
Image:
CSS:
#partners, #top {
position: relative;
z-index: 100;
}
#partners {
margin: 12px 0 3px;
text-align: center;
}
.clearfix:after, .row:after {
clear: both;
content: ".";
display: block;
height: 0;
visibility: hidden;
}
#partners .wrap {
width: 655px;
}
.wrap {
margin: 0 auto;
position: relative;
width: 990px;
}
#partners h2 {
color: #A6A5A5;
float: left;
font-weight: normal;
margin: 2px 15px 0 0;
}
#partners ul {
float: left;
}
ul {
list-style-position: outside;
list-style-type: none;
}
推荐答案
它的宽度为一些值,并添加margin:auto。
To center a div, set it's width to some value and add margin: auto.
#partners .wrap {
width: 655px;
margin: auto;
}
编辑,您要将div内容置中,而不是div本身。您需要更改 h2
, ul
和 li的显示属性
到 inline
,并删除 float:left
。
EDIT, you want to center the div contents, not the div itself. You need to change display property of h2
, ul
and li
to inline
, and remove the float: left
.
#partners li, ul, h2 {
display: inline;
float: none;
}
然后,它们将像普通文本元素一样布局, text-align属性,这是你想要的。
Then, they will be layed out like normal text elements, and aligned according to text-align property of their container, which is what you want.
这篇关于CSS中心内容div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!