英文:
Make image higher than wrapping div and starting from very bottom
问题
我无法将图像放置在一个div内,以便:
- 它比div更高,突出显示
- 从div的底部开始(有一个无法关闭的小间隙)
这是相关的HTML:
<div class="teaser-image-wrapper">
<div class="wrap">
<img class="image2 more-height" src="images/svg/creativeyou.svg" alt="Creative You! Title Image">
</div>
</div>
以及我拥有的CSS:
.teaser-image-wrapper {
background-color: #83ffcd;
width: 100% !important;
margin:
}
.wrap {
width: 80%;
}
.teaser-image-wrapper img {
padding: 0 !important;
object-fit: contain;
max-height: 75vh;
max-width: 100%;
line-height: 0;
}
这是一个参考图像:包装器(.teaser-image-wrapper)的绿色背景应该比应该从顶部突出的图像(svg)更低。还请注意底部的小间隙。
英文:
I am not able to position an image within a div so that:
- it's higher than the div and sticks out
- starts at the very bottom of the div (there is a small gap that I can't close)
This is the relevant HTML:
<div class="teaser-image-wrapper">
<div class="wrap">
<img class="image2 more-height" src="images/svg/creativeyou.svg" alt="Creative You! Title Image">
</div>
</div>
And the CSS I have:
.teaser-image-wrapper {
background-color: #83ffcd;
width: 100% !important;
margin:
}
.wrap {
width: 80%;
}
.teaser-image-wrapper img {
padding: 0 !important;
object-fit: contain;
max-height: 75vh;
max-width: 100%;
line-height: 0;
}
Here is an image for reference: The greenish background of the wrapper (.teaser-image-wrapper) should be lower than the image (svg) that should stick out on the top. Also, notice the little gap at the bottom.
Thank you for any hints
答案1
得分: 1
实现类似这样的效果最简单的方法可能是使用绝对定位和相对定位。可以尝试将类"wrap"设置为相对定位,将图像设置为绝对定位,使用以下样式:
left: 0;
right: 0;
bottom: 0;
然后可以调整"top"的位置,然后设置"wrap"类的高度以尝试实现所需的效果。可能有更好的方法来实现这个效果,但在不进行进一步调整的情况下,这是我脑海中首先想到的方法。希望这有所帮助。
英文:
The easiest way to achieve something like this could be to use position absolute and relative. Maybe try setting the class wrap to relative and the image absolute, with
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
left:0;
right:0;
bottom:0;
<!-- end snippet -->
and then play around with the position of 'top', can then set a height of the wrap class to try and achieve the desired effect. May be better ways to do this but without playing about with it this is what is off the top of my head. hope this helps
答案2
得分: 0
OK,经过一些调试,问题已解决。
我想要实现这个效果:
这是CSS代码。我基本上将包装器 - div 向下推,同时将内部的图像向上拉。
.teaser-image-wrapper {
max-width: 80%;
margin: 40vh 10% 0;
padding: 0;
line-height: 0;
}
.wrap {
width: 100%;
background-color: #83ffcd;
height: 50vh;
margin-top: 25vh;
}
.teaser-image-wrapper img {
padding: 0 !important;
object-fit: cover;
height: 75vh;
width: 100%;
line-height: 0;
position: relative;
margin-top: -25vh;
}
英文:
OK, after some tinkering solved it.
I wanted to achieve this:
This is the CSS. I basically push the wrapper - div down while pulling the image inside up.
.teaser-image-wrapper {
max-width: 80%;
margin: 40vh 10% 0;
padding: 0;
line-height: 0;
}
.wrap {
width: 100%;
background-color: #83ffcd;
height: 50vh;
margin-top: 25vh;
}
.teaser-image-wrapper img {
padding: 0 !important;
object-fit: cover;
height: 75vh;
width: 100%;
line-height: 0;
position: relative;
margin-top: -25vh;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论