html - 如何在网格中放置重叠两行的图像

标签 html css

所以我有一张 Pandas 图片,打算“挂”在我网页的黑线上,但问题是,它并没有降低 .top 部分 .background,它需要覆盖网格中的 .top.bottom 两部分。

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  background-color: #179CA5;
}

.background {
  display: grid;
  height: 100vh;
  width: 100vw;
  grid-template-rows: 3fr 5fr;
  grid-template-areas: "backgroundTop" "backgroundBottom";
}

.background .top {
  grid-area: backgroundTop;
  background-color: #179CA5;
}

.background .top img {
  display: block;
  margin: 10vh auto 0 auto;
  padding-right: 3vw;
  max-height: 13rem;
  max-width: 13rem;
  z-index: 1;
  position: relative;
  border: 3px orange solid;
}

.background .bottom {
  grid-area: backgroundBottom;
  color: white;
  background-color: black;
}
<body>
    <div class="background">
        <div class="top">
            <img src="https://i.imgur.com/ki4auk5.png" alt="Panda">
        </div>
        <div class="bottom">

        </div>
    </div>
</body>

网页:https://gyazo.com/e3bee60f6a873837c0f3241cd4a8e180

我创建了一个 jsfiddle帮助,你可以明白我的意思。

最佳答案

您可以在 img block 中简单地使用 top: 50px,更改 50px 以满足您的需要。

https://jsfiddle.net/7y91mdh4/

关于html - 如何在网格中放置重叠两行的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54259499/

相关文章:

html - 即使在使用 z-index : 2 之后,我的文本也没有以模糊效果显示在我的容器上

html - 使用 Bootstrap 4 将版权页脚定位到 Angular/C# 应用程序的底部

html - CSS 边框图像仅适用于顶部和底部

css - 是否有可能在 CSS 中重新排列表格而不产生间隙?

html - 如何排列要打印的 html 文档,这样页面就不会被截断?

java - 如何在 Swing 中使用 HTML

html - 使用 css 选择器对齐图像

在 CSS 中居中四列

javascript - HtmlService - 在选择元素中抑制 Firefox 箭头

html - 使网站适合窗口的视口(viewport),所有手机