0

我正在尝试很好地制作 div 空间中的所有子元素。我已经使用 inline-block 元素和浮动元素设置了 css。子元素是固定大小的。

jsFiddle

HTML

<div class="content">
    <h2>Inline-block</h2>
    <a href="#" class="i-b-item">I-B Item 1</a>
    <a href="#" class="i-b-item">I-B Item 2</a>
    <a href="#" class="i-b-item">I-B Item 3</a>
    <a href="#" class="i-b-item">I-B Item 4</a>
    <a href="#" class="i-b-item">I-B Item 5</a>
    <a href="#" class="i-b-item">I-B Item 6</a>
    <a href="#" class="i-b-item">I-B Item 7</a>
    <a href="#" class="i-b-item">I-B Item 8</a>
    <h2>Floated</h2>
    <a href="#" class="f-item">Float Item 1</a>
    <a href="#" class="f-item">Float Item 2</a>
    <a href="#" class="f-item">Float Item 3</a>
    <a href="#" class="f-item">Float Item 4</a>
    <a href="#" class="f-item">Float Item 5</a>
    <a href="#" class="f-item">Float Item 6</a>
    <a href="#" class="f-item">Float Item 7</a>
    <a href="#" class="f-item">Float Item 8</a>
    <div style="clear:both"></div>
</div>

CSS

.content {
    background: grey;
}

.content a{
    padding: .5em;
    margin: .5em;
    height: 75px;
    width: 150px;
    background: white;
}

.i-b-item{
    display: inline-block;
}

.f-item{
    float: left;
    display: block;
}

基本上当窗口大小发生变化时,我希望子元素边距使它们填充剩余空间。因此,我希望子元素的边距扩大到所有子元素的空间均匀,同时仍保持左对齐,而不是在右侧留出剩余空间。

我不想用 Javascript 做任何计算,我希望有一个纯 css 解决方案,但似乎无法让任何事情正常工作。

4

1 回答 1

0

用于text-align:justify子元素设置为的父元素display:inline-block

在你的情况下,.content类可以拥有它。并且您的空间将平均分配,而元素可以保持固定大小(宽度)。

.content {
    text-align:justify;
}

希望这可以帮助。

于 2013-09-20T23:15:37.483 回答