答案 0 :(得分:0)
向文档流添加元素时,会占用一些空间,导致其下方的内容向下移动。为防止这种情况发生,您基本上有两种选择:
position: absolute
。opacity: 0
或visibility: hidden
隐藏它。这样,它所需的空间已经在流程中保留。答案 1 :(得分:0)
position:absolute
或否定margin
div{
height:24px;
margin:10px 10px 0;
border:1px solid;
}
.somethinglarger{
margin-top:40px;
height:36px;
}
.error{
margin-bottom:-36px; /* 24px-height, 10px-margin top, 2px-border*/
}
.error2{
position:absolute;
}
.col{
width:30%;
height:auto;
float:left;
margin:0;
}

<div class="col">
<div class="somethinglarger">
Content 1
</div>
<div>
Content 2
</div>
<div>
Content 3
</div>
<!--div class="error">
Error message
</div-->
<div class="somethinglarger">
Content 4
</div>
</div>
<div class="col">
<div class="somethinglarger">
Content 1
</div>
<div>
Content 2
</div>
<div>
Content 3
</div>
<div class="error">
Error message
</div>
<div class="somethinglarger">
Content 4
</div>
</div>
<div class="col">
<div class="somethinglarger">
Content 1
</div>
<div>
Content 2
</div>
<div>
Content 3
</div>
<div class="error2">
Error message
</div>
<div class="somethinglarger">
Content 4
</div>
</div>
&#13;