Kellie Bottrell Kellie Bottrell - 6 months ago 41
CSS Question

Html5 and Css3 - Horizontal navigation bar issues

I am designing a webpage. I have two levels of navigation, the social media buttons on the first level and later a navigation bar. I am having issues getting the background colour of the navigation bar to go the complete length of the webpage, at present it starts and stops with the navigation bar. I am guessing it is an issue related to the location or my coding of the clearfix? Anyways I would appreciate your advice. My coding is below, I have attached a photo of my site so you can see what it looks like.

enter image description here

My Html code:

<div id="wrapper">
<header id="header" role="banner">
<div id="logo">
<a href="index.html"><img src="Images/title.png" alt="logo" width="1018" height="140"></a>
</div>
<div id="social">
<ul>
<li>
<a href="https://twitter.com/SaveADHCNSW#" target="_blank"><img src="images/twitter.png" alt="Twitter" width="32" height="32"></a>
</li>
<li>
<a href="https://www.facebook.com/Save-NSW-Government-Disability-
Services-ADHC-709029659182219/" target="_blank"><img src="images/facebook.png" alt="Facebook" width="32" height="32"></a>
</li>
<li>
<a href="https://www.youtube.com/channel/UCS0HQwz4LWWGS4AZhb5Ry3w" target="_blank"><img src="images/youtube.png" alt="Youtube" width="32" height="32"></a>
</li>
</ul>
</div>
<div id="clearfix">
</div>
<nav id="page_nav">
<div class="menu">
<ul id="navmenu">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="aboutus.html">About Us</a></li>
<li><a href="#">Get Involved</a><span class="darrow">&#9660;</span>
<ul class="submenu">
<li><a href="socialmedia.html">Social Media</a></li>
<li><a href="unionmeeting.html">Union Meetings</a></li>
<li><a href="rally.html">Rally</a></li>
</ul>
</li>
<li><a href="#">News</a><span class="darrow">&#9660;</span>
<ul class="submenu">
<li><a href="shrewsnews.html">Shrew's News</a></li>
<li><a href="update.html">Update</a></li>
</ul>
</li>
<li><a href="gallery.html">Gallery</a></li>
<li><a href="contacts.html">Contact Us</a></l>
</ul>
</div>
<div id="clearfix">
</div>
</div>
</nav>
</header>
</div>


My Css:

* {
margin: 0px;
padding: 0px;
}

body {
font-family: sans-serif;
background-color: black;
}

#wrapper {
width: 1366px;
height: auto;
background-color: black;
margin: 0 auto;
padding: 10px;
}

#header {
width: 100%;
height: 140px;
background-color: black;
}

#logo {
float: left;
margin: 0px 0px 20px 50px;
padding-left: 100px;
}

#social {
float: right;
top: 0px;
margin: 0 auto;
}

#social ul li {
float: left;
list-style: none;
padding: 5px;
}

#clearfix:after {
display: block;
clear: both;
}

#page_nav {
background-color: #c50a13;
}

ul#navmenu {
list-style-type: none;
width: 800px;
margin: auto auto 5px auto;
}

ul.submenu {
list-style-type: none;
}

ul#navmenu li {
outline: 1px solid white;
width: 125px;
text-align: center;
position: relative;
float: left;
margin-right: 4px;
color: #26b0f1;
}

ul#navmenu a {
text-decoration: none;
display: block;
width: 125px;
height: 25px;
line-height: 25px;
background-color: #c50a13;
border: 1px solid white;
border-radius: 5px;
color: white;
}

ul#navmenu .submenu a {
margin-top: 3px;
}

ul#navmenu li:hover > a {
background-color: white;
color: #c50a13;
}

ul#navmenu ul.submenu {
display: none;
position: absolute;
top: 26px;
left: 0px;
}

ul#navmenu li:hover .submenu {
display: block;
}

.darrow {
font-size: 14pts;
position: absolute;
top: 10px;
right: 1px;
color: dodgerblue;
}

Answer

Update:

You forgot something in your CSS clearfix.

#clearfix:after {
  display: block;
  clear: both;
  content: ''; /* add me */
}

In addition, you have some errors in your HTML which can affect rendering in different ways in different browsers.

[1] Invalid close tag for an <li>

[2] Extra </div> before the close of your </nav>.

[3] Duplicate IDs: id="clearfix"

First, fix the duplicate IDs. In your CSS, change this:

#clearfix:after {
  display: block;
  clear: both;
}

To this:

.clearfix:after {
  display: block;
  clear: both;
}

Here is your HTML without errors.

<div id="wrapper">
  <header id="header" role="banner">
    <div id="logo">
      <a href="index.html"><img src="Images/title.png" alt="logo" width="1018" height="140"></a>
    </div>
    <div id="social">
      <ul>
        <li>
          <a href="https://twitter.com/SaveADHCNSW#" target="_blank"><img src="images/twitter.png" alt="Twitter" width="32" height="32"></a>
        </li>
        <li>
          <a href="https://www.facebook.com/Save-NSW-Government-Disability-Services-ADHC-709029659182219/" target="_blank"><img src="images/facebook.png" alt="Facebook" width="32" height="32"></a>
        </li>
        <li>
          <a href="https://www.youtube.com/channel/UCS0HQwz4LWWGS4AZhb5Ry3w" target="_blank"><img src="images/youtube.png" alt="Youtube" width="32" height="32"></a>
        </li>
      </ul>
    </div>
    <div class="clearfix">
    </div>
    <nav id="page_nav">
      <div class="menu">
        <ul id="navmenu">
          <li class="active"><a href="index.html">Home</a></li>
          <li><a href="aboutus.html">About Us</a></li>
          <li>
            <a href="#">Get Involved</a><span class="darrow">&#9660;</span>
            <ul class="submenu">
              <li><a href="socialmedia.html">Social Media</a></li>
              <li><a href="unionmeeting.html">Union Meetings</a></li>
              <li><a href="rally.html">Rally</a></li>
            </ul>
          </li>
          <li>
            <a href="#">News</a><span class="darrow">&#9660;</span>
            <ul class="submenu">
              <li><a href="shrewsnews.html">Shrew's News</a></li>
              <li><a href="update.html">Update</a></li>
            </ul>
          </li>
          <li><a href="gallery.html">Gallery</a></li>
          <li><a href="contacts.html">Contact Us</a></li>
        </ul>
      </div>
      <div class="clearfix">
      </div>
    </nav>
  </header>
</div>
Comments