skip to Main Content

I am trying to position my content under my navbar and when I add the padding-top: 60px; it works but pushes the navbar down. I also need the background to be at the top of the page behind the navbar. How can I fix this? The content for the page including the navbar AND background are pushed down but I need the navbar and the background at the top of the page and only the content pushed down.

body {
    padding-top: 65px;
    margin: 0;
    width: 100%;
}

#header {
  background-color: grey;
  opacity: .7;
  width: 100%;
  height: 80px;
  position: fixed;
  z-index: 1000;
}

#logo a {
  font-size: 30px;
  font-weight: bold;
  color: rgb(255, 255, 255);
  font-family: 'DIN 1451 Std Engschrift';
  margin-top: 5px;
}

#slide1 {
  width: 100%;
  background: url('sunrise.png') 50% 0 no-repeat fixed;
  background-size: cover;
  color: #ffffff;
  height: 700px;
  margin: 0;
  padding: 40px 0 260px 0;
}

.content {
  margin: 0 auto;
  width: 1000px;
}
<div id="header">
        <div class="content">
    <nav id="nav" class="navbar navbar-expand-lg">
      <div id="logo">
        <a class="navbar-brand" href="#">Navbar Logo</a>
      </div>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
      <div id="logo">
        <div class="collapse navbar-collapse" id="navbarNav">
          <ul class="navbar-nav">
              <a class="nav-item nav-link" href="#slide3">How it Works</a>
              <a class="nav-item nav-link" href="#slide4">For Landlords</a>
              <a class="nav-item nav-link" href="#">F.A.Q</a>
              <a class="nav-item nav-link" href="#pricingslide">Pricing</a>
            </li>
          </ul>
        </div>
      </div>
    </nav>
  </div>
 </div>
    <body>
      <div id="slide1">
  <div class="content">
    <h1 id="headline">Use Your Rent To Buy A Home</h1>
    <p id="subtitle">Build a credit history, create a down payment,<br> all by just making rent payments thru LikeHome</p>
    <h3>Find out how soon you can become a homeowner?</h3>
    <%= render '_how_much_buying_form.html.erb' %>
  </div>
</div>
    </body>
    </html>

2

Answers


  1. First of all you need to correct the HTML markups. All html contents must be inside tag. Wrap the elements in a body tag, and create another div or section for contents followed by the header. And give padding to that div.

    Login or Signup to reply.
  2. Do this work for you?

    body {
      margin: 0;
      width: 100%;
    }
    
    #slide1 {
      background: url('http://res.cloudinary.com/sayob/image/upload/v1526907328/483257_vwhhfw.jpg') 50% 0 no-repeat fixed;
      background-size: cover;
      color: #ffffff;
      height: 700px;
      padding: 40px;
      margin-top: 20px;
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
    
    <nav id="nav" class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
      <div id="logo">
        <a class="navbar-brand" href="#">Navbar Logo</a>
      </div>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                  <span class="navbar-toggler-icon"></span>
                </button>
      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item">
            <a class="nav-link" href="#slide3">How it Works</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#slide4">For Landlords</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">F.A.Q</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#pricingslide">Pricing</a>
          </li>
        </ul>
      </div>
    </nav>
    
    <div class="container-fluid" id="slide1">
      <h1 id="headline">Use Your Rent To Buy A Home</h1>
      <p id="subtitle">Build a credit history, create a down payment,<br> all by just making rent payments thru LikeHome</p>
      <h3>Find out how soon you can become a homeowner?</h3>
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search