我正在尝试在1个父块中放置2个块。
.childright {
margin: 5px;
display: inline-block;
vertical-align: top;
background-color: #EEE;
border-radius: 4px;
height: 140px;
width: 405px;
position: relative;
}
.parent {
display: inline-block;
vertical-align: top;
background-color: blue;
border-radius: 4px;
height: 150px;
width: 500px;
}
.childleft {
margin-bottom: 5px;
border-radius: 4px;
height: 60px;
width: 60px;
margin-left: 5px;
display: inline-block;
background-color: #EEE;
vertical-align: middle;
top: 50%;
transform: translateY(70%);
}
HTML
<div class="parent" >
<div class="childleft"> </div>
<div class="childright"> </div>
</div>
以上作品。
但是下面的地方就像孩子一样。
<div class="span2">
<img class="span3" src="http://www.someimage.jpg" />
<p class="span1"> Random text</p>
</div>
你能告诉我这里出了什么问题吗?我是CSS的新手。
编辑:这是无法正常工作的网页。 http://www.ablueheart.com/uncategorized/2013-11-13/test
答案 0 :(得分:1)
p
div中有一个额外的空白span2
标记将其删除。
<div class="span2">
<img width="60" height="60" src="http://i0.wp.com/www.ablueheart.com/wp-content/uploads/2014/11/Jose-Mourinho-thumb.jpg?w=474" class="span3"></p>
<p class="span1"> text I’m vertically aligned! Hi ho Silver, away!I’m vertically aligned! Hi ho Silver, away!I’m vertically aligned! Hi ho Silver, away! I</p>
</div>
<div class="span2">
<img width="60" height="60" src="http://i0.wp.com/www.ablueheart.com/wp-content/uploads/2014/11/Jose-Mourinho-thumb.jpg?w=474" class="span3">
<p class="span1"> text I’m vertically aligned! Hi ho Silver, away!I’m vertically aligned! Hi ho Silver, away!I’m vertically aligned! Hi ho Silver, away! I</p>
</div>
答案 1 :(得分:0)
依赖于内联块会产生不确定的结果,因为标签之间的空格表现得像边距一样,并且根据你的字体大小或字母间距,.childright可能有也可能没有足够的空间。
将此添加到您的CSS应该可以解决您的问题:
.childleft, .span3 { float:left; }
.childright, .span1 { float:right; }
答案 2 :(得分:0)
我在类“span1”,“span2”,“span3”中进行了一些修改,并删除了属性“transform:translateY(70%);”在课程“span3”中:demo
.span3{
background-color: #eee;
border-radius: 4px;
display: inline-block;
height: 60px;
margin-bottom: 5px;
margin-left: 0px;
width: 60px;
}
div.span3{
margin-left: 5px;
margin-top: 41px;
}
.span2 {
background-color: blue;
border-radius: 4px;
display: inline-block;
height: 150px;
vertical-align: top;
width: 500px;
}
.span1 {
background-color: #eee;
border-radius: 4px;
display: inline-block;
height: 140px;
margin: 5px;
position: relative;
vertical-align: top;
width: 405px;
}
div.span1{
margin-left: 5px;
}
<div class="span2">
<div class="span3" > <img width="60" height="60" class="span3" src="http://i0.wp.com/www.ablueheart.com/wp-content/uploads/2014/11/Jose-Mourinho-thumb.jpg?w=474"></div>
<div class="span1">
<p class="span1" style="margin: 0px;"> text I’m vertically aligned! Hi ho Silver, away!I’m vertically aligned! Hi ho Silver, away!I’m vertically aligned! Hi ho Silver, away! I</p>
</div>
</div>