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 do I center a fixed header and body text?

I’m trying to make a small website, and I’ve figured out how to make a header and footer. The issue is, the header stops on the left side of the page and does not stop on the right. The footer stops in both direction. I want both the header and footer to reach the edges of the page. How do I do this? Additionally, how do I ensure body text is an equal distance from both the header and footer? Thanks!

body {
  padding-top: 150px;
  /*dear god. save yourself. ALWAYS have padding you actual fool.>*/
  padding-bottom: 40px;
}

p {
  color: black;
  margin-left: 50px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: medium;
}

.fixed-header {
  width: 100%;
  position: fixed;
  background: black;
  color: white;
  text-align: center;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: large;
  top: 0;
}

.footer {
  bottom: 0;
  height: 100px;
  width: 100%;
  padding-bottom: 0%;
  background-color: black;
  text-align: center;
  line-height: 100px;
  /*set line height=height to center text vertically!*/
  color: white;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

a:link,
a:visited,
a:hover,
a:active {
  text-decoration: none;
}

.container {
  width: 100%;
  margin: 0;
}

nav a {
  color: #fff;
  text-decoration: none;
  padding: 5px 35px 10px;
  display: inline-block;
  width: 15%;
  height: auto;
}

a {
  color: white;
}
<DOCTYPE! html>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <html lang="en-US">

  <head>
    <link rel="stylesheet" href="css-attempt.css">
    <title>Hmm</title>
  </head>

  <body>
    <div class="fixed-header">
      <h1><a href="index.html">Hmm</a></h1>
      <div class="container">
        <nav>
          <a href="#">About</a>
          <a href="#">Resources</a>
          <a href="#">Projects</a>
          <a href="#">Connect</a>
          <a href="#">Donate</a>
        </nav>
      </div>
    </div>
    <p> Took way too long to understand why this text wasn't showing up. 6 hours of my life I'm never getting back.</p>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <p> Do you ever feel like a plastic bag?</p>
    <div class="container">
      <div class="footer">This is a footer. It's here because the content ends here.</div>
    </div>
  </body>

I’ve tried adjusting padding, margins, and basically everything I could think of, given I have maybe two weeks of experience with coding.

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 :

Your body has a margin from the user agent stylesheet. Override this by setting margin to zero for the body.

body {
  padding-top: 150px;
  /*dear god. save yourself. ALWAYS have padding you actual fool.>*/
  padding-bottom: 40px;
  margin: 0;
}

p {
  color: black;
  margin-left: 50px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: medium;
}

.fixed-header {
  width: 100%;
  position: fixed;
  background: black;
  color: white;
  text-align: center;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: large;
  top: 0;
}

.footer {
  bottom: 0;
  height: 100px;
  width: 100%;
  padding-bottom: 0%;
  background-color: black;
  text-align: center;
  line-height: 100px;
  /*set line height=height to center text vertically!*/
  color: white;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

a:link,
a:visited,
a:hover,
a:active {
  text-decoration: none;
}

.container {
  width: 100%;
  margin: 0;
}

nav a {
  color: #fff;
  text-decoration: none;
  padding: 5px 35px 10px;
  display: inline-block;
  width: 15%;
  height: auto;
}

a {
  color: white;
}
<DOCTYPE! html>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <html lang="en-US">

  <head>
    <link rel="stylesheet" href="css-attempt.css">
    <title>Hmm</title>
  </head>

  <body>
    <div class="fixed-header">
      <h1><a href="index.html">Hmm</a></h1>
      <div class="container">
        <nav>
          <a href="#">About</a>
          <a href="#">Resources</a>
          <a href="#">Projects</a>
          <a href="#">Connect</a>
          <a href="#">Donate</a>
        </nav>
      </div>
    </div>
    <p> Took way too long to understand why this text wasn't showing up. 6 hours of my life I'm never getting back.</p>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <p> Do you ever feel like a plastic bag?</p>
    <div class="container">
      <div class="footer">This is a footer. It's here because the content ends here.</div>
    </div>
  </body>
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