调整 div 的宽度以适应其包含多个 div 的内容
我有一个小问题。
实际上我正在尝试调整“内容”的宽度以适应其中的多个div。事实上,我正在尝试使这段代码适应多个屏幕,我无法指定特殊的宽度。内联块根本不起作用。我不知道为什么。我会将 div 内容放在页面的中间,并将类放在 div 内容的中间。事实上,这是一个完美的中心。
有想法吗?
HTML
<div id="content">
<div class="badges"></div>
<div class="badges"></div>
<div class="badges"></div>
<div class="badges"></div>
<div class="badges"></div>
<div class="badges"></div>
<div style="clear:both;"></div>
</div>
CSS
#content{
display:inline-block;
}
.badges{
width:220px;
height:380px;
float:left;
background:red;
margin:10px;
}
谢谢, 巴斯蒂安
I have a small problem.
Actually I'm trying to adapt the width of "content" to multiple div in it. In fact, I'm trying to adapt this code to several screens, I can't specified a special width. The inline-block doesn't work at all. I don't know why. I would center the div content in the middle of my page and center classes in the middle of the div content. A perfect center in fact.
Have an idea?
HTML
<div id="content">
<div class="badges"></div>
<div class="badges"></div>
<div class="badges"></div>
<div class="badges"></div>
<div class="badges"></div>
<div class="badges"></div>
<div style="clear:both;"></div>
</div>
CSS
#content{
display:inline-block;
}
.badges{
width:220px;
height:380px;
float:left;
background:red;
margin:10px;
}
Thanks,
Bastien
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用浮动。
试试这个:
这就是
inline-block
应该如何使用。另外,按照 Kai Qing 的说法更正您的标记。
Don't use float.
Try this:
That's how
inline-block
should be used.Also, correct your markup as Kai Qing says.
对于其中之一,您应该使用实际的 div 关闭标签而不是 span 来关闭您的 div。然后也关闭该清除 div
for one you should close your divs with actual div closing tags and not span. Then close that clearing div as well