Search code examples
javascripthtmlcssbackground-imagenavigationbar

How to add navigation bar on a image


First day of me learning to code in html and css. I'm trying to add navigation bar on a image but i am unable to do so. The background image i am trying to add is not displaying too. Can anyone help me out here.

.header {
  background-image: url("vent1.jpg");
}

.nav {
  overflow: hidden;
  float: left;
  background-color: #333;
  margin: 0px;
  padding: 0px;
  list-style-type: none;
}

.menu-bar {
  list-style-type: none;
  text-align: center;
}

.ul {
  display: inline-block;
  padding: 8px;
  margin: 0px;
  color: white;
}
<div class="header">
  <div class="nav">
    <div class="menu-bar">
      <ul>
        <li><a href="#contact"> Home</a></li>
        <li>
          <a href="#aboutus"></a>About Us</li>
        <li>
          <a href="#portfolio"></a>Portfolio</li>
        <li>
          <a href="#contact"></a>Contact</li>
      </ul>
    </div>
  </div>
</div>


Solution

  • header class should have these properties.

    .header {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-image: url("vent1.jpg");
      background-repeat: no-repeat;
      background-size:cover;
    
    }