-2

I am using a banner that fills my entire screen, a hero banner, and when i add a content div below it the text just displays over the banner. i belive the problem is something to do with the "absolute" positioning of my hero banner. but if i change the positioning the text on the banner goes crazy. any ideas?

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>

Tried to switch the positioning but didnt work.

Rickard Elimää
  • 7,107
  • 3
  • 14
  • 30

1 Answers1

0

If you have sections A and B and you want section B to appear below section A, then you need to use the default position: static; for both of them. That lays out the sections according to the normal flow. As soon as you use absolute positioning for either A or B, it’s taken out of the flow and it won't affect the position of anything else in the document except its own children.

https://developer.mozilla.org/en-US/docs/Web/CSS/position

Brett Donald
  • 6,745
  • 4
  • 23
  • 51