固定 DIV 问题中的另一个居中 DIV
我在这里尝试一个非常简单的过程,基本上是尝试将客户徽标集中在这个主要客户 div 中。我最近刚刚开始从事网页设计业务,虽然我可以阅读一些解决方案,但我在将它们应用到我的结构中时遇到了困难。
基本上我有几个客户端框,每个客户端框内都有一个 PNG 图像:
<div id="clients">
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
</div>
我希望能够将客户端框集中在具有固定权重的客户端 div 上。我尝试过使用 display: inline-block 但这似乎没有多大作用。我假设这是因为我已经强迫它们浮动:向左,但我不知道如何在不这样做的情况下保持它们在 div 中的位置。就像我说的,我对 CSS 是个新手,这就是我为所有 CSS 所做的事情。
这是我为客户端和客户端框 CSS 所做的:
#clients {
background-image: url("img/images/clients_bg.png");
border-bottom: 1px solid #333333;
border-top: 1px solid #666666;
float: left;
margin-top: 120px;
padding: 10px;
width: 778px;
}
.client-box {
background: none repeat scroll 0 0 #bcb546;
float: left;
font-family: verdana;
font-size: 11px;
height: 60px;
margin-right: 10px;
opacity: 0.8;
padding-top: 40px;
text-align: center;
width: 100px;
}
.client-box:hover {
opacity: 1;
}
根据我的理解,这应该不难实现,但到目前为止我还没有任何运气,可能是因为我的大脑专注于某种做事方式,而它只是不会让步。任何帮助将不胜感激。
您可以在此处查看实时网站。
谢谢你。
I am attempting a very simple procedure here, basically trying to center the client logos within this main clients div. I've just recently started with this web design business and while I can read some of the solutions out there, I'm having trouble applying them to my structure.
Basically I have a few client boxes, each is going to have a PNG image inside of them:
<div id="clients">
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
</div>
I'd like to be able to center the client-box's on the client's div that has a fixed weight. I've tried using display: inline-block but that didn't seem to do much. I'm assuming that's because I've already forced them to float: left but I don't know how I can maintain their position in the div without doing so. Like I said I'm quite a novice with CSS and this is what I've been doing for all my CSS.
Here's what I have for clients and client-box CSS:
#clients {
background-image: url("img/images/clients_bg.png");
border-bottom: 1px solid #333333;
border-top: 1px solid #666666;
float: left;
margin-top: 120px;
padding: 10px;
width: 778px;
}
.client-box {
background: none repeat scroll 0 0 #bcb546;
float: left;
font-family: verdana;
font-size: 11px;
height: 60px;
margin-right: 10px;
opacity: 0.8;
padding-top: 40px;
text-align: center;
width: 100px;
}
.client-box:hover {
opacity: 1;
}
From my understanding, this shouldn't be hard to achieve, but so far I have not had any luck probably because my brain is fixated on a certain way of doing things and it just won't budge. Any help would be greatly appreciated.
You can see the live site here.
Thank you SO.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
float: left
强制display: block
,因此display: inline-block
不会产生任何效果。在
.client-box
上,您需要:float: left
display: inline-block
。最后,在父元素(
#clients
)上,您需要添加text-align: center
。float: left
forcesdisplay: block
, sodisplay: inline-block
would have no effect.On
.client-box
, you need to:float: left
display: inline-block
.Finally, on the parent element (
#clients
), you need to addtext-align: center
.如果外部 div 具有固定宽度,您可以设置内部 div 的边距以占据适当的空间。
例如:
CSS
或者您可以使用 margin-left: auto;右边距:自动;然而,这(就像世界上其他一切一样)在 IE 中不起作用。
希望这有帮助!
If your outer div is of a fixed width you can set the margins for the inner div to take up the appropriate space.
eg:
CSS
Alternatively you can use margin-left: auto; margin-right: auto; however that (like everything else in the world) doesn't work in IE.
Hope this helps!
我将向客户端框添加一个包装器,其宽度等于客户端框的总宽度。
例如,在您上面发布的实时站点中,有 5 个客户端框,每个框的宽度为 100 像素,右边距为 10 像素。因此,添加一个宽度为 5 x (100 +10) = 550px 的 div 包装器,并将包装器以“margin-left:auot”和“margin-right:auto”居中。
I will add a wrapper to the client-boxes, whose width is equal to the total width of client-boxes.
For example, in the live site you post above, there are 5 client boxes, and each of them are 100px width with 10px margin-right. So add a div wrapper with width 5 x (100 +10) = 550px, and center the wrapper with "margin-left:auot" and "margin-right:auto".