我在codepen page上有以下代码。 (出于代码运行目的而包括-不在代码段中起作用)目标是能够在<div class="item__boxes">
的底部显示<div class="item">
元素。
问题
如何在<div class="item__boxes">
底部显示<div class="item">
元素?
目标:
<div class="item__text">
的高度由于其中的内容而增加,因此文本和<div class="item__boxes">
之间应该始终有一些填充/边距。<div class="item__boxes">
应该始终显示在<div class="item">
元素的底部,而不考虑断点。当前问题
所需的输出
代码
.item {
position: relative;
}
.item__wrapper {
max-width: 50%;
position: relative;
}
.item__img img {
width: 100% !important;
}
.item__text {
position: absolute;
background: rgba(238, 238, 238, 0.5);
padding: 64px;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 5;
display: flex;
flex-direction: column;
justify-content: center;
}
.item__boxes {
background-color: #ccc;
display: flex;
position: absolute;
bottom: 0;
}
.col-padding {
padding: 16px;
}
.col-m-12 {
width: 100%;
}
@media (min-width: 1024px) {
.col-t-6 {
width: 50%;
}
}
<div class="item__wrapper">
<div class="item">
<div class="item__img">
<picture>
<source media="(min-width: 1300px)" srcset="https://placeimg.com/1000/480/nature">
<source media="(min-width: 1024px)" srcset="https://placeimg.com/960/480/nature">
<img src="https://placeimg.com/640/480/nature" alt="Flowers" style="width:auto;">
</picture>
</div>
<div class="item__text">
<h3>Some title</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
<div class="item__boxes">
<div class="col-m-12 col-t-6 col-padding">
<div>Some Title</div>
<div>Enthusiastically incubate diverse initiatives without multifunctional strategic theme areas.</div>
</div>
<div class="col-m-12 col-t-6 col-padding">
<div>Globally Title</div>
<div>Globally impact integrated infomediaries via seamless mindshare. </div>
</div>
<div class="col-m-12 col-t-6 col-padding">
<div>Distinctively Title</div>
<div>Distinctively strategize long-term high-impact ideas whereas client-centered leadership skills.</div>
</div>
</div>
</div>
答案 0 :(得分:0)
我玩过你的代码。
为了无论宽度有多大,总是需要填充,您必须在文本上使用相对位置并绝对定位图像。填充底部的宽度会依其宽度而异,我建议您将图像作为background-image
包括在内,并在CSS中将背景图像的大小设置为cover
,无论您的屏幕有多宽/窄/矮/矮,这种方式都不会出现间隙。我尝试了给定代码的宽度为80%,并将填充设置为33%(我没有放入背景图片代码),在初始宽度为50%时,不需要底部填充。
由于css结构,该代码段代码无法运行,但无论如何我都将其包括在内以供将来参考。这是codepen link和second one
希望这会有所帮助
.item {
position: relative;
&__wrapper {
max-width: 50%;
position: relative;
min-height: 100vh;
}
&__img {
img {
top: 0px;
position: absolute;
width: 100%!important;
}
}
&__text {
top: 0px;
position: relative;
min-height: 100vh;
background: rgba(238, 238, 238, 0.5);
padding-right: 50px;
padding-left: 50px;
padding-top: 30px;
//padding-bottom:33vh at 80%;
z-index: 0;
display: flex;
flex-direction: column;
align-items: top;
justify-content: center;
}
&__boxes {
background-color: #ccc;
display: flex;
position: relative;
bottom: 0px;
}
}
.col {
&-padding {
padding: 16px 16px 5px 16px;
}
&-m-12 {
width: 100%;
}
}
@media (min-width: 1024px) {
.col {
&-t-6 {
width: 50%;
}
}
}
<div class="item__wrapper">
<div class="item">
<div class="item__img">
<picture>
<source media="(min-width: 1300px)" srcset="https://placeimg.com/1000/480/nature">
<source media="(min-width: 1024px)" srcset="https://placeimg.com/960/480/nature">
<img src="https://placeimg.com/640/480/nature" alt="Flowers" style="width:auto;">
</picture>
</div>
<div class="item__text">
<h3>Some title</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally
procrastinate. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
<div class="item__boxes">
<div class="col-m-12 col-t-6 col-padding">
<div>Some Title</div>
<div>Enthusiastically incubate diverse initiatives without multifunctional strategic theme areas.</div>
</div>
<div class="col-m-12 col-t-6 col-padding">
<div>Globally Title</div>
<div>Globally impact integrated infomediaries via seamless mindshare. </div>
</div>
<div class="col-m-12 col-t-6 col-padding">
<div>Distinctively Title</div>
<div>Distinctively strategize long-term high-impact ideas whereas client-centered leadership skills.</div>
</div>
</div>
</div>