これは私が持っている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