当我在父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之间获得统一的间距?
答案 0 :(得分: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;
}
答案 1 :(得分:0)
使用此css正在运行DEMO HERE
#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 */
}
答案 2 :(得分: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;
}
答案 3 :(得分:0)
这是小提琴链接http://jsfiddle.net/SNSvU/11/。授予#prioritiesWrapper
overflow:hidden
和#prioritiesWrapper div.priority
float:left
。我想是的。