均匀移动盒子的边距
我有这样的代码:
<style type="text/css">
body > div { height: 260px; overflow: hidden; }
div div { float: left; height: 250px; width: 250px; margin: 1px; background: #ccc; }
</style>
<div>
<div>first 1</div>
<div>first 2</div>
<div>first 3</div>
<div>first 4</div>
<div>first 5</div>
</div>
我不会给这个框留出边距以均匀地移动它们。
I have this code:
<style type="text/css">
body > div { height: 260px; overflow: hidden; }
div div { float: left; height: 250px; width: 250px; margin: 1px; background: #ccc; }
</style>
<div>
<div>first 1</div>
<div>first 2</div>
<div>first 3</div>
<div>first 4</div>
<div>first 5</div>
</div>
I wonna give margins to this boxes to shift them evenly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于容器的宽度未知,并且 div 的宽度以像素为单位固定(排除基于百分比的系统) - 您无法使用 CSS 做到这一点。
您可以使用 http://matthewjamestaylor.com/blog/beautiful-css-centered-menus-no-hacks-full-cross-browser-support或者你可以看看JavaScript(或者你可以设置父级的宽度元素到已知值)。
Since the width of the container is unknown, and the width of the divs is fixed in pixels (ruling out a percentage based system) - you can't do this with CSS.
You could centre them using the technique described at http://matthewjamestaylor.com/blog/beautiful-css-centered-menus-no-hacks-full-cross-browser-support or you could look towards JavaScript (or you could set the width of the parent element to a known value).