I have a navigation bar on my website.
The HTML:
<nav id="navigation">
<a href="index.html"> <h1>My Cooking Webpage</h1> </a>
<ul>
<li>
<a href="nav/recipes.html" class="right_categories">Recipes</a>
</li>
<li>
<a href="nav/categories.html" class="right_categories">Categories</a>
<ul id="subcategories">
<li>
<a href="#">Item 1</a>
</li>
<li>
<a href="#">Item 2</a>
</li>
<li>
<a href="#">Item 3</a>
</li>
</ul>
</li>
<li>
<a href="nav/about.html" class="right_categories">About Us</a>
</li>
</ul>
</nav>
The CSS:
#navigation {
font-size: 24px;
float: right;
}
#featured-image {
width: 800px;
height: 600px;
}
.breadcrumb {
font-size: 20px;
}
#subcategories {
display: none;
}
nav {
display: block;
position: relative;
}
nav li {
display: block;
margin-right: 10px;
float: right;
}
nav li:hover #subcategories {
display: block;
}
nav a {
color: white;
}
nav ul {
padding: 0px;
list-style-type: none;
}
#featuredtext {
position: relative;
}
#page-background {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#wrapper {
position: relative;
z-index: 1;
padding: 10px;
}
#slider_wrapper {
width: 100%;
text-align: center;
}
#navigation {
width: 100%;
}
My DOCTYPE is HTML5 (<!DOCTYPE html>) if that helps.
The problem is that when I hover over the “Categories” link, the drop-down box drops horizontally rather than vertically. When I put <br />s in between the <li>s, the HTML doesn’t validate.
I think it is because of the float: right; in the CSS, though I tried to correct it with float: none;.
Is there a way to make it drop down vertically rather than horizontally, or is there an alternative to <br />. I want the HTML to validate through the W3C validators, HTML and CSS.
The only valid child element of a
<ul>is a<li>. Style the<li>‘s top and bottom margins using CSS to pad their vertical distance. Remove thefloatstyle altogether to have them appear as block elements lined up vertically.