1

我试图弄清楚为什么我在父 div 中平铺一系列 div 时会出现间距问题。这是小提琴:http: //jsfiddle.net/SNSvU/4/。这就是我所拥有的:

HTML

<div id="prioritiesWrapper">
<div class="priority"><div class="img">Img here</div><div class="title">This is my priority title</div></div>
<div class="priority"><div class="img">Img here</div><div class="title">This is my priority title; it's longer than the others and wraps</div></div>
<div class="priority"><div class="img">Img here</div><div class="title">This is my priority title</div></div>
<div class="priority"><div class="img">Img here</div><div class="title">This is my priority title</div></div>
<div class="priority"><div class="img">Img here</div><div class="title">This is my priority title; it's longer than the others and wraps</div></div>
<div class="priority"><div class="img">Img here</div><div class="title">This is my priority title; it's longer than the others and wraps</div></div>
<div class="priority"><div class="img">Img here</div><div class="title">This is my priority title</div></div>
<div class="priority"><div class="img">Img here</div><div class="title">This is my priority title</div></div>
<div class="priority"><div class="img">Img here</div><div class="title">This is my priority title</div></div>
<div class="priority"><div class="img">Img here</div><div class="title">This is my priority title</div></div>

CSS

#prioritiesWrapper {
    color: white;
    background-color: blue;
    margin: 0 auto;
}

#prioritiesWrapper .priority .img {
    float: left;
    height: 50px;
    margin: 0 15px 0 0;
}

#prioritiesWrapper .priority .title {
    margin: auto 0;
}

#prioritiesWrapper div.priority {
    width: 350px;
    height: 80px;
    display: inline-block;
    margin: 10px 30px;
    padding: 10px;
    background-color: black;
    text-align: left;
    font-weight: bold;
    line-height: 2em;
}

只要给定行上的优先级标题都相似(一行或两行),div 之间的间距似乎很好,但如果它们不同,它会使另一个 div 不对齐。

无论内容行如何,如何在 div 之间获得统一的间距?

4

4 回答 4

0

这是小提琴链接http://jsfiddle.net/SNSvU/11/。给#prioritiesWrapper overflow:hidden#prioritiesWrapper div.priority float:left。我想就是这样。

于 2013-09-17T12:57:51.763 回答
0

像这样?http://jsfiddle.net/SNSvU/5/

#prioritiesWrapper div.priority
{
width: 600px;
height: 80px;
display: inline-block;
margin: 10px 30px;
padding: 10px;
background-color: black;
text-align: left;
font-weight: bold;
line-height: 2em;
}

或者你想让它像这样更有活力吗?http://jsfiddle.net/SNSvU/6/

#prioritiesWrapper div.priority
{
width: auto;
height: 80px;
display: block;
margin: 10px 30px;
padding: 10px;
background-color: black;
text-align: left;
font-weight: bold;
line-height: 2em;
}
于 2013-09-17T12:41:05.580 回答
0

在此处使用此 css 工作演示

#prioritiesWrapper div.priority {
width: 350px;
height: 80px;
display: inline-block;
margin: 10px 30px;
padding: 10px;
background-color: black;
text-align: left;
font-weight: bold;
line-height: 2em;
vertical-align: middle;/* ADDED */
}
于 2013-09-17T12:45:54.717 回答
0

如果您不关心 div 的高度,则将 height 属性更改为 auto... 像这样

#prioritiesWrapper div.priority
{
width: 350px;
height: auto;
display: inline-block;
margin: 10px 30px;
padding: 10px;
background-color: black;
text-align: left;
font-weight: bold;
line-height: 2em;
}  

在这里提琴

于 2013-09-17T12:49:04.107 回答