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

s4n0splo  于 2023-03-09  发布在  其他
关注(0)|答案(1)|浏览(115)

我使用的是一个充满整个屏幕的横幅,一个英雄横幅,当我在它下面添加一个内容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>

尝试切换定位,但不起作用。

sz81bmfz

sz81bmfz1#

如果你有A节和B节,并且你想让B节出现在A节的下面,那么你需要对它们都使用默认的position: static;。这会根据正常的流程来布局节。一旦你对A节或B节使用绝对定位,它就会从流程中移除,并且除了它自己的子节之外,它不会影响文档中其他任何东西的位置。
https://developer.mozilla.org/en-US/docs/Web/CSS/position

相关问题