使图像高于包裹的 div 并从底部开始

huangapple go评论69阅读模式
英文:

Make image higher than wrapping div and starting from very bottom

问题

我无法将图像放置在一个div内,以便:

  1. 它比div更高,突出显示
  2. 从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:

  1. it's higher than the div and sticks out
  2. starts at the very bottom of the div (there is a small gap that I can't close)

This is the relevant HTML:

 &lt;div class=&quot;teaser-image-wrapper&quot;&gt;
   &lt;div class=&quot;wrap&quot;&gt;
    &lt;img class=&quot;image2 more-height&quot; src=&quot;images/svg/creativeyou.svg&quot; alt=&quot;Creative You! Title Image&quot;&gt;
   &lt;/div&gt;
 &lt;/div&gt;

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.

使图像高于包裹的 div 并从底部开始

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,经过一些调试,问题已解决。

我想要实现这个效果:

使图像高于包裹的 div 并从底部开始

这是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:

使图像高于包裹的 div 并从底部开始

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;
}

huangapple
  • 本文由 发表于 2020年1月3日 19:01:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577393.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定