如何使图像从其容器的底部开始?

发布于 2024-11-30 18:46:08 字数 142 浏览 4 评论 0原文

我在一个带有 overflow:hidden; 的短容器内有一个高图像。图像的底部被切除。如何使顶部而不是底部被切断?

戏剧化

I have a tall image inside a short container with overflow: hidden;. The bottom of the image is cut off. How do I make the top get cut off instead of the bottom?

dramatized

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

被你宠の有点坏 2024-12-07 18:46:08

为容器提供以下 css:

position:relative;

为图像提供以下 css:

position:absolute;
bottom:0px;

PS
顺便说一句,插图非常好(而且清晰)

give the container the following css:

position:relative;

and the image the following css:

position:absolute;
bottom:0px;

P.S.
Very nice (and clear) illustrations btw

红ご颜醉 2024-12-07 18:46:08

如果您的图像只是容器的 background-image,请执行以下操作:

#container {
    background: url(your-image.jpg) no-repeat bottom left;
}

否则,将 img 元素定位到容器的底部,如 @Joseph 建议的那样:

#container {
    position:relative;
}

#container img {
    position: absolute;
    bottom: 0px;
}

If your image is just the background-image of the container, do this way:

#container {
    background: url(your-image.jpg) no-repeat bottom left;
}

Otherwise, position the img element to the bottom of the container, like @Joseph suggested:

#container {
    position:relative;
}

#container img {
    position: absolute;
    bottom: 0px;
}
秋叶绚丽 2024-12-07 18:46:08

例如,如果容器的高度为 300px,则此方法有效:

.container {
  overflow: hidden;
  height: 300px;
  position: relative;
}

.image {
  position: absolute;
  bottom: 0;
}

If the container has a 300px height for example, this works:

.container {
  overflow: hidden;
  height: 300px;
  position: relative;
}

.image {
  position: absolute;
  bottom: 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文