Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I stop an element's background from flowing into the rest of the page?

I’m very new to coding (I’ve only been at this a couple of weeks). I’m playing around with building a basic web page. I have a with a brownish background color. Everything seemed to be working fine, however, when I try to add content outside of the background-color continues to extend.

Is there a way to add new text to the starting below so that the text appears against the green background?

body {
  background-color: #A3B18A;
}

#wrap {
  background-color: #DAD7CD;
  margin: 20px;
  border-radius: 25px;
  /* this is a pretty nifty trick */
  box-shadow: 10px 5px 5px grey;
}

#bodywrap {
  font-family: verdana;
  text-align: center;
  margin-bottom: 10px;
}

#header {
  font-family: fantasy;
  font-size: 50px;
  text-align: center;
  padding-left: 60px;
  line-height: 20px;
}

#header h6 {
  color: #5b616A;
  font-family: sans-serif;
}

nav {
  border-radius: 10px;
  font-size: 30px;
}

nav li {
  display: inline-block;
  padding: 20px;
}

nav ul {
  list-style: none;
  display: flex;
  justify-content: center;
}

nav a {
  text-decoration: none;
  color: #5b616A;
  font-family: fantasy;
}

a:hover,
a:active {
  text-decoration: underline;
}
<body>
  <div id="wrap">
    <nav>
      <ul>
        <li><a href="about.html">Home</a></li>
        <li><a href="education.hmtl"> Education </a></li>
        <li><a href="contact.html"> Contact Me</a></li>
        <li><a href="blog.html"> Blog</a></li>
      </ul>
    </nav>
    <div id="header">
      <h2>A lot of nothing</h2>
      <h6> Even more nothing</h6>
    </div>
    <div id="bodywrap">
      <p> Just adding more text here.</a></p>
      <br>
      <br>
      <br>
      <br>
      <br>
      <p> This text will appear with a brown background, how do I get it to appear on the green background?.</p>

    </div>

    <div id="footer">
      <footer>

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

</html>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is because your footer section is in wrap div. Move footer out of wrap and will be ok. Also you have a close </a> with is not necessary here <p> Just adding more text here.</a></p>

body {
  background-color: #a3b18a;
}

#wrap {
  background-color: #dad7cd;
  margin: 20px;
  border-radius: 25px;
  /* this is a pretty nifty trick */
  box-shadow: 10px 5px 5px grey;
}

#bodywrap {
  font-family: verdana;
  text-align: center;
  margin-bottom: 10px;
}

#header {
  font-family: fantasy;
  font-size: 50px;
  text-align: center;
  padding-left: 60px;
  line-height: 20px;
}

#header h6 {
  color: #5b616a;
  font-family: sans-serif;
}

nav {
  border-radius: 10px;
  font-size: 30px;
}

nav li {
  display: inline-block;
  padding: 20px;
}

nav ul {
  list-style: none;
  display: flex;
  justify-content: center;
}

nav a {
  text-decoration: none;
  color: #5b616a;
  font-family: fantasy;
}

a:hover,
a:active {
  text-decoration: underline;
}
<div id="wrap">
    <nav>
        <ul>
        <li><a href="about.html">Home</a></li>
        <li><a href="education.hmtl"> Education </a></li>        
        <li><a href="contact.html"> Contact Me</a></li>
        <li><a href="blog.html"> Blog</a></li>
        </ul>
    </nav>   
    <div id="header">
        <h2>A lot of nothing</h2>
        <h6> Even more nothing</h6>
    </div>
    <div id="bodywrap">
        <p> Just adding more text here.</a></p>
        <br>
        <br>
        <br>
        <br>
        <br>    
    </div>
</div>

 <div id="footer">
      <footer>
          <p> This text will appear with a brown background, how do I get it to appear on the green background?.</p>
      </footer>
  </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading