0
我試圖創建一個佈局,其中一個元素(.figure)在中心對齊時比它的高度短容器(.timeline-content)。但是當元素長於容器時,我希望元素與容器的高度相同。當高度小於容器時垂直居中元素,但當容器高度小時高度爲100%
容器本身的高度取決於其父項。
This image should help clarify the desired behavior. 這就是我現在所擁有的,我不明白爲什麼IMG延伸過去其父儘管它的最大高度:100%
https://jsfiddle.net/kgdkyte4/3/
html{
position: relative;
}
.timeline-item{
width: 100%;
overflow:hidden
}
.timeline-content{
width: 50%;
float: left;
text-align: right;
}
.timeline-image{
display:flex;
align-items: center;
position:absolute;
right: 0;
width: 50%;
height:100%;
}
.figure{
width:100%;
max-height: 100%;
margin: 0;
position:relative;
}
img{
max-height:100%;
max-width:100%;
float:left;
}
<div class="timeline-item">
<div class="timeline-content">
<h3 class="timeline-title">Blah blah blah
</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum a ornare sem. In sodales ac nisl facilisis pharetra. Nam non pellentesque mauris. Proin scelerisque, sapien non scelerisque auctor, nunc erat condimentum est, viverra dapibus dui odio a neque. Mauris est dui, posuere at urna in, gravida tincidunt odio. Integer quis egestas est. Praesent tincidunt justo nec nibh malesuada ullamcorper. Nulla convallis et quam vitae posuere.
</p>
</div>
<div class="timeline-image">
<figure class="figure">
<img src="http://via.placeholder.com/550x900">
<figcaption class="figure-caption">blah
</figcaption>
</figure>
</div>
</div>
設定高度:100%;和最大高度到一個px值到img – buxbeatz
@buxbeatz哪個元素? 。數字? –
沒有實際的 – buxbeatz