块这是HTML我有:中心垂直上方的另一个块的底线
<div class="image">Image</div>
<div class="legend">
Legend<br/>
width variable height<br/>
the middle of the legend need to be exactly on the bottom of the image, regardless of the height of the legend and image
</div>
<div class="following">The following text should follow immediatly the legend,regardless of the height of the legend or the image</div>
这是我想要的结果:
这是我的尝试:
.image {
height:100px;
background-color:red;
}
.legend {
transform:translateY(-50%);
background-color:blue;
width:300px;
margin:0 auto
}
.following {
background-color:yellow;
margin-top:-45px;
}
问题是:我不希望在图例和下面的文本之间有这个边距。
The whole attempt codepen is here
问题:任何解决方案,得到期望的结果,而不JS?
(备案:this is a solution with JS)
不,我不知道的任何元素的高度 – sylvain
而你需要该元素为“上去”这是高度的整整50%? – Dekel
正好在中间 – sylvain