无论高度如何,如何将图像定位在剖面的底部。我确实尝试了相对和绝对的位置,但它并没有顺利。请原谅我的英文,我希望截图和实时网址能更好地解释。
https://codepen.io/anon/pen/VrxdKe
HTML
<section class="green fifty">
<div class="inner-content">
<h1>
Test Test Test
</h1>
<img src="http://www.quanmax.com/site/wp-content/uploads/2017/06/test.png" />
</div>
</section>
<section class="blue fifty">
<div class="inner-content">
<h1>
Test Test Test
</h1>
<img src="http://www.quanmax.com/site/wp-content/uploads/2017/06/test.png" />
</div>
</section>
CSS
.green {
background: green;
}
.blue {
background: blue;
}
.fifty {
height: 50vh;
max-width: none;
width: 100%;
display: table;
}
.inner-content {
padding:20px 20px 0px 20px;
display: table-cell;
}
更好地解释屏幕截图:http://prntscr.com/he3jxl
由于
答案 0 :(得分:1)
absolute
定位在嵌套的absolute
元素上使用img
定位。
/* Additional */
.inner-content img {
position: absolute;
bottom: 0; /* adjust to suit requirements */
}
摘要:
absolute
bottom
属性值relative
(要求)代码段示范:
.green {
background: green;
}
.blue {
background: blue;
}
.fifty {
height: 100vh; /* adjusted for the sake of demonstration */
max-width: none;
width: 100%;
display: table;
}
.inner-content {
padding:20px 20px 0px 20px;
display: table-cell;
position: relative; /* additional (required) */
}
/* Additional */
.inner-content img {
position: absolute;
bottom: 0; /* adjust to suit requirements */
}
&#13;
<section class="green fifty" style="height: 200vh;">
<div class="inner-content">
<h1>
The sibling image is positioned <code>absolute</code>
</h1>
<img src="http://www.quanmax.com/site/wp-content/uploads/2017/06/test.png" />
</div>
</section>
<section class="blue fifty">
<div class="inner-content">
<h1>
The sibling image is positioned <code>absolute</code>
</h1>
<img src="http://www.quanmax.com/site/wp-content/uploads/2017/06/test.png" />
</div>
</section>
&#13;
table-cell
显示其他包含元素在其他嵌套元素包装table-cell
上使用img
显示。
/* Additional */
.inner-content_cell {
display: table-cell;
vertical-align: bottom;
height: 100vh; /* adjust to suit requirements */
}
摘要:
img
并显示table-cell
代码段示范:
.green {
background: green;
}
.blue {
background: blue;
}
.fifty {
height: 100vh; /* adjusted for demonstration */
max-width: none;
width: 100%;
display: table;
}
.inner-content {
padding:20px 20px 0px 20px;
display: table-cell;
}
/* Additional */
.inner-content_cell {
display: table-cell;
vertical-align: bottom;
height: 100vh; /* adjust to suit requirements */
}
&#13;
<section class="green fifty">
<div class="inner-content">
<h1>
The sibling element is displayed <code>table-cell</code>
</h1>
<div class="inner-content_cell">
<img src="http://www.quanmax.com/site/wp-content/uploads/2017/06/test.png" />
</div>
</div>
</section>
<section class="blue fifty">
<div class="inner-content">
<h1>
The sibling element is displayed <code>table-cell</code>
</h1>
<div class="inner-content_cell">
<img src="http://www.quanmax.com/site/wp-content/uploads/2017/06/test.png" />
</div>
</div>
</section>
&#13;
答案 1 :(得分:0)
以下代码使用了position relative&amp;绝对。 无论高度如何,它都能正常工作。
.green {
background: green;
}
.blue {
background: blue;
}
.fifty {
height: 400px;
max-width: none;
width: 100%;
display: table;
}
.inner-content {
padding: 20px 20px 0px 20px;
display: table-cell;
position: relative;
}
.inner-content img {
position: absolute;
bottom: 0;
}
&#13;
<section class="green fifty">
<div class="inner-content">
<h1>
Test Test Test
</h1>
<img src="http://www.quanmax.com/site/wp-content/uploads/2017/06/test.png" />
</div>
</section>
<section class="blue fifty">
<div class="inner-content">
<h1>
Test Test Test
</h1>
<img src="http://www.quanmax.com/site/wp-content/uploads/2017/06/test.png" />
</div>
</section>
&#13;
有关解释的任何进一步细节。随时发表评论。