div之间的间距相等

时间:2014-10-08 05:24:06

标签: html css html5 css3

Demo

嗨,我这里有三个div。我想在它的左右两侧给出相等的间距。我想让它变得通用。

我面临的问题

1.If i add more div's , it requires many CSS changes
2. What if content length increases? It ll decrease it's spacing.
3. I want to make it possible without using width and inline-block.

如果有任何解决方案,请告诉我。如果我们'必须'使用宽度或内联块,也建议。提前致谢。我的css如下:

.wrapper
{
  width: 100%;
  height: 60px;
  background-color: #454545;
}

.div1,.div2,.div3
{
  float: left;
  margin: 0 15% 0 10%;
  color: #fff;
}

1 个答案:

答案 0 :(得分:1)

如果更改内容或更改列数,则您使用的方法将无法使用。据我所知,以下是可能的解决方案:

<强>选项1:

.div {
    width:33.33%;
    display:inline-block;
}

缺点:

1)inline-block在元素之间留下空白。注释元素之间的空格,即

2)因为,列被赋予width,随着列的更改,宽度需要更改。

Demo here.

<强>选项2:

.wrapper {
    display:table;
    table-layout:fixed;
    width:100%;
}
.div {
    display:table-cell;
}

缺点:

1)在IE7中不起作用。

Demo here.

相关问题