塊這是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