如何添加方形部分并整合它们

问题描述 投票:0回答:1

嗨,我不知道,如果我的问题很愚蠢,但我正在绕过 CSS 定位 Flexbox 和所有这些东西,但我真的想让我的网站更引人注目?这就是我的想法。 enter image description here

到目前为止,我真的希望这个方形部分覆盖我的具有背景图像的英雄部分。就像这张照片或类似的东西。不需要提供代码(尽管很感激),但我只是想知道这项技术。谢谢

css flexbox css-position
1个回答
0
投票

对于“覆盖”或将一个元素覆盖在另一个元素上,一种简单的解决方案是在覆盖层上使用负边距,并结合下面元素上的额外填充。

body {
  margin: 0;
  font-family: sans-serif;
  background: #f4f4f4;
}

.banner {
  background-image: url(http://picsum.photos/1280/600);
  background-size: cover;
  color: white;
  padding: 2em 30vw 70px 10vw;
  text-shadow: 0 0 5px rgb(0 0 0 / 0.5);
  box-sizing: border-box;
}

button {
  background: darkorange;
  color: white;
  border: 0;
  font-size: 1em;
  border-radius: 4px;
  padding: 10px 30px;
}

.box {
  background: white;
  font-size: 2em;
  font-weight: bold;
  width: 80%;
  margin: -35px auto 0 auto;
  padding: 30px;
  box-sizing: border-box;
  display: flex;
  gap: 1em;
  justify-content: center;
}

main {
  padding: 2em 10vw;
}
<div class="banner">
  <h1>Banner text blah blah blah</h1>
  <p><button>Learn more</button></p>
</div>

<div class="box">
  <div>3M+</div>
  <div>3.2M</div>
  <div>170</div>
</div>

<main>
  <p>Page continues</p>
</main>

© www.soinside.com 2019 - 2024. All rights reserved.