如何将内容放在英雄横幅下方,它目前是重叠的

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

我正在使用一个充满整个屏幕的横幅,一个英雄横幅,当我在它下面添加一个内容 div 时,文本只显示在横幅上。我相信这个问题与我的英雄旗帜的“绝对”定位有关。但如果我改变定位,横幅上的文字就会变得疯狂。有什么想法吗?

body,
html {
  height: 100%;
  width: 100%;
  font-size: 100%;
  background-color: #333;
}

h1 {
  font-size: 5em;
}

h2 {
  font-size: 2.5em;
}

#content {
  font-family: sans-serif;
  margin: 0.5%;
  font-size: 170%;
  border: 10px outset orange;
  color: white;
  text-align: justify;
  padding: 1.5%;
  line-height: 125%;
  position: absolute;
}


/* The hero image */

.hero-image {
  /* Use "linear-gradient" to add a darken background effect to the image (photographer.jpg). This will make the text easier to read */
  background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("blackred.webp");
  /* Set a specific height */
  height: 100%;
  width: 100%;
  /* Position and center the image to scale nicely on all screens */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: center;
}


/* Place text in the middle of the image */

.hero-text {
  font-family: 'Arial';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  text-align: center;
}


/* Navbar container */
.navbar {
  overflow: hidden;
  background-color: #333;
  font-family: Arial;
}


/* Links inside the navbar */
.navbar a {
  float: left;
  font-size: 16px;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}


/* The dropdown container */

.dropdown {
  float: left;
  overflow: hidden;
}


/* Dropdown button */

.dropdown .dropbtn {
  font-size: 16px;
  border: none;
  outline: none;
  color: white;
  padding: 14px 16px;
  background-color: inherit;
  font-family: inherit;
  /* Important for vertical align on mobile phones */
  margin: 0;
  /* Important for vertical align on mobile phones */
}


/* Add a red background color to navbar links on hover */

.navbar a:hover,
.dropdown:hover .dropbtn {
  background-color: white;
  color: black;
}


/* Dropdown content (hidden by default) */

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}


/* Links inside the dropdown */

.dropdown-content a {
  float: none;
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}


/* Add a grey background color to dropdown links on hover */

.dropdown-content a:hover {
  background-color: #ddd;
}


/* Show the dropdown menu on hover */

.dropdown:hover .dropdown-content {
  display: block;
}

.button {
  background-color: black;
  border: 2px solid white;
  border-color: #FFFFF;
  color: white;
  padding: 10px 30px;
  text-align: center;
  display: inline-block;
  font-size: 16px;
}

.button:hover {
  background-color: white;
  color: black;
}
<html>

<body>
  <div class="navbar">
    <a href="home.htm">Home</a>
    <a href="signup.htm">Sign up</a>
    <div class="dropdown">
      <button class="dropbtn">Our teams ▼
    </button>
      <div class="dropdown-content">
        <a href="LOL.htm">League of legends</a>
        <a href="valorant.htm">Valorant</a>
        <a href="RL.htm">Rocket league</a>
      </div>
    </div>
  </div>
  <div class="hero-image">
    <div class="hero-text">
      <img src="RCLOGO.png" alt="RCLOGO">
      <h2>E sports team</h2>
      <a class="button" href="signup.htm">Join now</a>
    </div>
    <div class="content">
    </div>
    <div class="footer">
    </div>
  </div>

</body>

</html>

尝试切换定位但没有用。

html css banner
1个回答
0
投票

如果您有 A 部分和 B 部分,并且希望 B 部分出现在 A 部分下方,那么您需要对它们都使用默认的

position: static;
。这根据正常流程布置了部分。一旦你对 A 或 B 使用绝对定位,它就会从流中取出,它不会影响文档中除了它自己的孩子之外的任何其他内容的位置。

https://developer.mozilla.org/zh-CN/docs/Web/CSS/position

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