【问题标题】:Margins to shift boxes evenly均匀移动盒子的边距
【发布时间】:2009-06-05 21:11:41
【问题描述】:

我有这个代码:

<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>

我不会给这些框留出边距以使它们均匀移动。

【问题讨论】:

    标签: html margin


    【解决方案1】:

    由于容器的宽度未知,并且 div 的宽度以像素为单位固定(排除基于百分比的系统)- 你不能用 CSS 做到这一点。

    您可以使用http://matthewjamestaylor.com/blog/beautiful-css-centered-menus-no-hacks-full-cross-browser-support 中描述的技术将它们居中,或者您可以查看 JavaScript(或者您可以将父元素的宽度设置为已知值)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-27
      • 2012-11-07
      • 2014-07-04
      • 1970-01-01
      • 2012-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多