将浮动左侧 div 在主体中居中
我有这段代码
<body>
<? while.. (blah blah blah){ ?>
<div class="product">
something
</div>
<? } ?>
</body>
,css文件的
.product{ width:350px; float:left; }
问题是主体没有宽度,嗯......实际上它有90%,但我的问题是在不同的分辨率上,它对我来说非常适合(1680px宽度),但是当我切换到 1024 时,产品似乎已关闭(向左对齐)
是否有可能将这些 div 在其父容器上使用非静态居中?
i have this piece of code
<body>
<? while.. (blah blah blah){ ?>
<div class="product">
something
</div>
<? } ?>
</body>
and the css file is
.product{ width:350px; float:left; }
the problem is that body doesn´t have a width, well... actually it has, 90%, but my problem is on the different resolutions, it works perfect for me (1680px width) but when i switch to 1024 as example, the products seems to be off (aligned to the left)
is there any posibility to center those divs with a non static with on their parent container?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想要多个 div,全部作为一个组居中,则必须将它们包装在父 div 中,然后使用边距将其居中。
您的另一个选择是使它们
display: inline;
并在正文上使用text-align: center
将它们居中。 (或者考虑使它们成为跨度,默认为内联)If you want multiple divs, all centered as a group, you'll have to wrap them in a parent div, then center that using margins.
Your other option would be to make them
display: inline;
and usetext-align: center
on the body to center them. (Or consider making them spans, which default to inline)如果你关闭浮动,你可以使用
if you turn floating off, you can use
如果您为 div 声明一个百分比宽度,然后执行
margin-left:auto;
、margin-right:auto;
,这样可以吗?您可以给图像一些左右填充,这应该使您的图像居中。
If you declare a width in percentage for the div, and then do
margin-left:auto;
,margin-right:auto;
, would that be OK?You could give the images some left and right padding and that should make your images centered.