So the navigation bar is meant to be the height of the page and is fixed, so will always show, even when the user scrolls down the page.
However my .nav is currently looking like this
Help would be greatly appreciated. Also, when creating a responsive website, what should the image size be? Like when creating the image on Photoshop, how large should the canvas be the ensure the image isn't blurry?
HTML and CSS is as follows
.nav {
list-style-type: none;
margin: 0;
padding: 0;
height: 100%;
width: 25%;
position: fixed;
top: -15px;
left: -10px;
}
.nav li a {
display: block;
background-color: #232121;
/*padding-bottom: 73.5px;*/
padding-left: 25px;
/*padding-top: 20px;*/
text-decoration: none;
color: white;
font-weight: 600;
letter-spacing: 2px;
}
.nav li a:hover {
color: #00b4ff;
text-decoration: none;
}
.sub-nav {
list-style-type: none;
background-color: #232121;
color: white;
}
.sub-nav li a {
font-weight: 400;
letter-spacing: 1px;
}
.sub-nav li a:hover {
color: #00b4ff;
text-decoration: none;
font-weight: 400;
}
<ul class="nav">
<li>
<a href="index.html">
<img src="logo1.jpg" alt="logo" class="logo">
</a>
</li>
<li>HOME
</li>
<li>ABOUT
</li>
<li>PRODUCTS
</li>
<li>SALES AND MOTIVATION
<ul class="sub-nav">
<li>SALES SUCCESS
</li>
<li>MOTIVATION
</li>
</ul>
</li>
<li>PROPERTY INVESTMENT
<ul class="sub-nav">
<li>CURRENT LISTINGS
</li>
<li>TESTIMONIALS
</li>
</ul>
</li>
<li>CONTACT
<ul class="sub-nav">
<li>SUBSCRIBE
</li>
</ul>
</li>
<li>CONNECT
</li>
<li>
<a href="facebook.com">
<img src="facebook.jpg" alt="facebook" class="facebook">
</a>
</li>
<li>
<a href="twitter.com">
<img src="twitter.jpg" alt="twitter" class="twitter">
</a>
</li>
<li>
<a href="linkedin.com">
<img src="linkedin.jpg" alt="linkedin" class="linkedin">
</a>
</li>
</ul>
you are having your background-color: #232121 in your .nav li a just changed to your .nav and your .nav was set top:-15px, I changed for top:0
SNIPPET:
.nav {
list-style-type: none;
margin: 0;
padding: 0;
height: 100%;
width: 25%;
position: fixed;
top: 0;
left: -10px;
background-color: #232121;
}
.nav li a {
display: block;
/*padding-bottom: 73.5px;*/
padding: 0 25px;
/*padding-top: 20px;*/
text-decoration: none;
color: white;
font-weight: 600;
letter-spacing: 2px;
}
.nav li a:hover {
color: #00b4ff;
text-decoration: none;
}
.nav li a img {
max-width: 100%
}
.sub-nav {
list-style-type: none;
background-color: #232121;
color: white;
}
.sub-nav li a {
font-weight: 400;
letter-spacing: 1px;
}
.sub-nav li a:hover {
color: #00b4ff;
text-decoration: none;
font-weight: 400;
}
<ul class="nav">
<li>
<a href="index.html">
<img src="//lorempixel.com/300/300" alt="logo" class="logo">
</a>
</li>
<li>HOME
</li>
<li>ABOUT
</li>
<li>PRODUCTS
</li>
<li>SALES AND MOTIVATION
<ul class="sub-nav">
<li>SALES SUCCESS
</li>
<li>MOTIVATION
</li>
</ul>
</li>
<li>PROPERTY INVESTMENT
<ul class="sub-nav">
<li>CURRENT LISTINGS
</li>
<li>TESTIMONIALS
</li>
</ul>
</li>
<li>CONTACT
<ul class="sub-nav">
<li>SUBSCRIBE
</li>
</ul>
</li>
<li>CONNECT
</li>
<li>
<a href="facebook.com">
<img src="facebook.jpg" alt="facebook" class="facebook">
</a>
</li>
<li>
<a href="twitter.com">
<img src="twitter.jpg" alt="twitter" class="twitter">
</a>
</li>
<li>
<a href="linkedin.com">
<img src="linkedin.jpg" alt="linkedin" class="linkedin">
</a>
</li>
</ul>
We could use a bit more code, to figure what is going on with your particular website; just pasting the nav code isn't very helpful.
That being said, let's keep things simple. This how you create a basic fixed sidebar nav. Obviously a lot depends on your specific code, but since we don't have that, we can only guess what's going on and I'm guessing you didn't set height to 100% on the nav's parent element and upstream to the other parents or body.
If you supply more details, perhaps we can elaborate as to what is going on.
body {
height: 100%;
position: relative;
margin: 0;
}
main {
background: red;
height: 1000px;
padding-left: 100px;
}
aside {
background: lightblue;
height: 100%;
position: fixed;
top: 0;
left: 0;
width: 100px;
}
<aside>
links here
</aside>
<main>
this is your main content
</main>
Actually, the .nav is having 100% height now, but the problem is that it doesn't have the background color. You should set background-color: #232121; to .nav too.
As of the cropped words, you have to give the div a width to make sure the words would not be out of boundary.
.nav {
background-color: #232121;
height: 100%;
width: 225px;
position: fixed;
top: 0;
left: -10px;
list-style-type: none;
margin: 0;
padding: 0;
background-color: #232121;
}
.nav li a {
display: block;
background-color: #232121;
width: 200px;
/*padding-bottom: 73.5px;*/
padding-left: 25px;
/*padding-top: 20px;*/
text-decoration: none;
color: white;
font-weight:600;
letter-spacing: 2px;
}
.nav li a:hover {
color: #00b4ff;
text-decoration: none;
}
.sub-nav {
list-style-type: none;
background-color: #232121;
color: white;
}
.sub-nav li a {
font-weight: 400;
letter-spacing: 1px;
padding: 0;
width: 185px;
}
.sub-nav li a:hover {
color: #00b4ff;
text-decoration: none;
font-weight: 400;
}
<ul class="nav">
<li><img src="logo1.jpg" alt="logo" class="logo"></li>
<li>HOME</li>
<li>ABOUT</li>
<li>PRODUCTS</li>
<li>SALES AND MOTIVATION
<ul class="sub-nav">
<li>SALES SUCCESS</li>
<li>MOTIVATION</li>
</ul>
</li>
<li>PROPERTY INVESTMENT
<ul class="sub-nav">
<li>CURRENT LISTINGS</li>
<li>TESTIMONIALS</li>
</ul>
</li>
<li>CONTACT
<ul class="sub-nav">
<li>SUBSCRIBE</li>
</ul>
</li>
<li>CONNECT</li>
<li><img src="facebook.jpg" alt="facebook" class="facebook"></li>
<li><img src="twitter.jpg" alt="twitter" class="twitter"></li>
<li><img src="linkedin.jpg" alt="linkedin" class="linkedin"></li>
</ul>
edit your Css like:
.nav {
list-style-type: none;
margin: 0;
padding: 0;
height: 100px;
width: 100%;
position: fixed;
left: -10px;
/*border: 1px solid red;*/
}
.nav li
{
display: inline;
}
.nav li a {
background-color: #232121;
/*padding-bottom: 73.5px;*/
padding-left: 25px;
/*padding-top: 20px;*/
text-decoration: none;
color: white;
font-weight:600;
letter-spacing: 2px;
}
And html file to :
<!DOCTYPE html>
<html>
<head>
<title>Learning Input</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<ul class="nav">
<li><img src="logo1.jpg" alt="logo" class="logo"></li>
<li>HOME</li>
<li>ABOUT</li>
<li>PRODUCTS</li>
<li>SALES AND MOTIVATION
<!-- <ul class="sub-nav">
<li>SALES SUCCESS</li>
<li>MOTIVATION</li>
</ul> -->
</li>
<li>PROPERTY INVESTMENT
<!-- <ul class="sub-nav">
<li>CURRENT LISTINGS</li>
<li>TESTIMONIALS</li>
</ul> -->
</li>
<li>CONTACT
<!-- <ul class="sub-nav">
<li>SUBSCRIBE</li>
</ul> -->
</li>
<li>CONNECT</li>
<li><img src="facebook.jpg" alt="facebook" class="facebook"></li>
<li><img src="twitter.jpg" alt="twitter" class="twitter"></li>
<li><img src="linkedin.jpg" alt="linkedin" class="linkedin"></li>
</ul>
</body>
</html>
Related
I am making a multi-list dropdown navigation, and below that I want some text or a photo to be displayed. Since my navbar has a position of absolute, the text is appearing behind the navbar rather than below it. Is there a way that I can get my text to appear below without using a margin or padding on the element or container beneath the nav?
Currently the "fix" that I have been using is to add a style of margin-top: 4rem or the same with padding to my h1 to get it to show under the nav rather than behind it.
Since I want to use this navigation bar on multiple pages though with differing content, I am hoping to not need to continuously find the element below the navigation and add that padding/margin to it. Is there any other way or do I just need to use the current "solution"?
Here is my codepen
Snippet below:
html,
body {
margin: 0;
padding: 0;
}
header {
height: 100px;
background: black;
}
nav {
position: absolute;
left: 0px;
right: 0px;
width: 100%;
background: #363636;
}
nav .nav-container {
width: 80%;
margin: auto;
}
nav .third-level-menu {
list-style-type: none;
position: absolute;
top: 0;
right: -15rem;
width: 15rem;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
nav .third-level-menu > li {
height: auto;
background: #414141;
}
nav .second-level-menu {
list-style-type: none;
position: absolute;
top: 4rem;
left: 0;
width: 15rem;
list-style: none;
padding: 0;
margin: 0;
display: none;
font-size: 0.5rem;
letter-spacing: 0.1ch;
text-indent: 1rem;
font-size: 1rem;
}
nav .second-level-menu > li {
list-style-type: none;
position: relative;
height: 4rem;
background: #474747;
text-align: left;
}
nav .top-level-menu {
list-style-type: none;
list-style: none;
padding: 0;
margin: 0;
float: left;
line-height: normal;
text-align: center;
height: auto;
}
nav .top-level-menu > li {
position: relative;
float: left;
height: 4rem;
width: 9.4rem;
background: #363636;
font-size: 1.2rem;
}
nav .top-level-menu a {
color: #e8e8e8;
text-decoration: none;
padding: 0 1rem;
display: block;
line-height: 4rem;
text-transform: uppercase;
}
#media screen and (min-width: 1023px) {
.top-level-menu li:hover > ul {
display: inline;
}
}
<header>
</header>
<nav class="nav">
<div class="nav-container">
<ul class="top-level-menu">
<li>Home</li>
<li>
More
<ul class="second-level-menu">
<li>
<a>Wyoming</a>
<ul class="third-level-menu">
<li>Wyoming li</li>
<li>Wyoming li</li>
<li>Wyoming li</li>
<li>Wyoming li</li>
</ul>
</li>
<li>
<a>Washington</a>
<ul class="third-level-menu">
<li>Washington</li>
<li>Washington</li>
</ul>
</li>
<li>
<a>Idaho</a>
<ul class="third-level-menu">
<li>Idaho Falls</li>
<li>Idaho Falls</li>
<li>Idaho Falls</li>
<li>Idaho Falls</li>
<li>Idaho Falls</li>
<li>Idaho Falls</li>
</ul>
</li>
<li>
<a>Minnesota</a>
<ul class="third-level-menu">
<li>Duluth</li>
</ul>
</li>
<li>
<a>Montana</a>
<ul class="third-level-menu">
<li>Montana</li>
<li>Montana</li>
<li>Montana</li>
<li>Montana</li>
</ul>
</li>
<li>
<a>South Dakota</a>
<ul class="third-level-menu">
<li>SD</li>
<li>SD</li>
</ul>
</li>
<li>
<a>North Dakota</a>
<ul class="third-level-menu">
<li>Idaho</li>
<li>Idaho</li>
<li>Idaho</li>
<li>Idaho</li>
<li>Idaho</li>
</ul>
</li>
</ul>
</li>
<li>
Sale
<ul class="second-level-menu">
<li>Ogden, UT</li>
<li>Ogden, UT</li>
<li>Ogden, UT</li>
<li>Ogden, UT</li>
</ul>
</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
</nav>
<br>
<h1>HELLO IS ANYONE THERE?</h1>
I added a div with an id of 'navspace'. This will need to be added to every page underneath the nav.
Then I added a line of javascript which makes this div the same height as the nav. All other elements will therefore appear below the nav.
document.getElementById("navspace").style.height = document.getElementsByTagName('nav')[0].offsetHeight + "px";
html,
body {
margin: 0;
padding: 0;
}
header {
height: 100px;
background: black;
}
nav {
position: absolute;
left: 0px;
right: 0px;
width: 100%;
background: #363636;
}
nav .nav-container {
width: 80%;
margin: auto;
}
nav .third-level-menu {
list-style-type: none;
position: absolute;
top: 0;
right: -15rem;
width: 15rem;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
nav .third-level-menu>li {
height: auto;
background: #414141;
}
nav .second-level-menu {
list-style-type: none;
position: absolute;
top: 4rem;
left: 0;
width: 15rem;
list-style: none;
padding: 0;
margin: 0;
display: none;
font-size: 0.5rem;
letter-spacing: 0.1ch;
text-indent: 1rem;
font-size: 1rem;
}
nav .second-level-menu>li {
list-style-type: none;
position: relative;
height: 4rem;
background: #474747;
text-align: left;
}
nav .top-level-menu {
list-style-type: none;
list-style: none;
padding: 0;
margin: 0;
float: left;
line-height: normal;
text-align: center;
height: auto;
}
nav .top-level-menu>li {
position: relative;
float: left;
height: 4rem;
width: 9.4rem;
background: #363636;
font-size: 1.2rem;
}
nav .top-level-menu a {
color: #e8e8e8;
text-decoration: none;
padding: 0 1rem;
display: block;
line-height: 4rem;
text-transform: uppercase;
}
#media screen and (min-width: 1023px) {
.top-level-menu li:hover>ul {
display: inline;
}
}
<header>
</header>
<nav class="nav">
<div class="nav-container">
<ul class="top-level-menu">
<li>Home</li>
<li>
More
<ul class="second-level-menu">
<li>
<a>Wyoming</a>
<ul class="third-level-menu">
<li>Wyoming li</li>
<li>Wyoming li</li>
<li>Wyoming li</li>
<li>Wyoming li</li>
</ul>
</li>
<li>
<a>Washington</a>
<ul class="third-level-menu">
<li>Washington</li>
<li>Washington</li>
</ul>
</li>
<li>
<a>Idaho</a>
<ul class="third-level-menu">
<li>Idaho Falls</li>
<li>Idaho Falls</li>
<li>Idaho Falls</li>
<li>Idaho Falls</li>
<li>Idaho Falls</li>
<li>Idaho Falls</li>
</ul>
</li>
<li>
<a>Minnesota</a>
<ul class="third-level-menu">
<li>Duluth</li>
</ul>
</li>
<li>
<a>Montana</a>
<ul class="third-level-menu">
<li>Montana</li>
<li>Montana</li>
<li>Montana</li>
<li>Montana</li>
</ul>
</li>
<li>
<a>South Dakota</a>
<ul class="third-level-menu">
<li>SD</li>
<li>SD</li>
</ul>
</li>
<li>
<a>North Dakota</a>
<ul class="third-level-menu">
<li>Idaho</li>
<li>Idaho</li>
<li>Idaho</li>
<li>Idaho</li>
<li>Idaho</li>
</ul>
</li>
</ul>
</li>
<li>
Sale
<ul class="second-level-menu">
<li>Ogden, UT</li>
<li>Ogden, UT</li>
<li>Ogden, UT</li>
<li>Ogden, UT</li>
</ul>
</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
</nav>
<div id="navspace"></div>
<br>
<h1>HELLO IS ANYONE THERE?</h1>
for some reason my menu bar (its fixed) is in 2 lines in chrome browser and normal in all other browsers. Any idea why or how to fix it? I tried to figure it out but i didnt fix it. Is it a problem with browser default block height or what? I need to make it work on chrome and on all other browsers too.
JsFiddle: https://jsfiddle.net/wkupr9L6/1/
HTML:
<script>
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 65) {
$("nav").css("opacity", "0.2");
}
else {
$("nav").css("opacity", "1");
}
});
</script>
</head>
<body>
<!--MENU BAR!-->
<nav class="navig">
<span class="nadpis"> RPO </span>
<ul class="nav">
<li class="prve">Dátumy
<ul>
<li>1-7/7/2016
<ul>
<li>1/7/2016</li>
<li>2/7/2016</li>
<li>3/7/2016</li>
<li>4/7/2016</li>
<li>5/7/2016</li>
<li>6/7/2016</li>
<li>7/7/2016</li>
</ul>
</li>
<li>8-14/7/2016
<ul>
<li>8/7/2016</li>
<li>9/7/2016</li>
<li>10/7/2016</li>
<li>11/7/2016</li>
<li>12/7/2016</li>
<li>13/7/2016</li>
<li>14/7/2016</li>
</ul>
</li>
<li>15-21/7/2016
<ul>
<li>15/7/2016</li>
<li>9/7/2016</li>
<li>10/7/2016</li>
<li>11/7/2016</li>
<li>12/7/2016</li>
<li>13/7/2016</li>
<li>14/7/2016</li>
</ul>
</li>
</ul>
</li>
<li class="druhe">☰
<ul>
<li> FLV
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> FLC
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> QUA
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> HFX
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> PDT
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul></li>
<li> RSH
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> BUR
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> SUHRN </li>
<li> INCI </li>
<li> JIRA </li>
<li> CHGT </li>
<li> TASK </li>
<li> VRS </li>
</div>
</ul>
</li>
</ul>
</nav>
CSS:
body, nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav {
display: inline-block;
position: fixed;
width: 100%;
text-align: center;
background-color: #111;
vertical-align: top;
top: -1px;
opacity: 1;
transition: 0.3s;
}
nav:hover {
opacity: 1!important;
background-color: #111;
transition: 0.3s;
}
.nav a {
display: block;
background: #111;
color: #fff;
text-decoration: none;
padding: 0.7em 1.7em;
text-transform: uppercase;
font-size: 85%;
letter-spacing: 3px;
position: relative;
}
.nav{
vertical-align: top;
display: inline-block;
}
.nav li {
position: relative;
}
.nav > li {
float: left;
margin-right: 1px;
}
.nav li:hover > a {
transition: 0.3s;
background-color:#3a3939;
color: #40d23b;
}
.nav ul {
position: absolute;
white-space: nowrap;
z-index: 1;
left: -99999em;
background-color: #000;
border: 2px solid #81D4FA;
border-top: none;
}
.nav > li:hover > ul {
left: auto;
min-width: 100%;
}
.nav > li li:hover > ul {
left: 100%;
top:-1px;
}
.nav > li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
}
.nav li li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
right: 10px;
}
.prve{
max-width:125px;
min-width: 90px;
border: 2px solid #81D4FA;
border-bottom: none;
border-top: none;
}
.druhe {
max-width: 14px;
min-width: 110px;
border-right: 2px solid #81D4FA;
}
span {
float:left;
margin-left: 3px;
}
span a{
text-decoration: none;
color:#2670CF;
background-color:#111;
font-family: 'Helvetica Neue', sans-serif;
font-size: 30px;
font-weight: bold;
}
Thanks for help
This doesn't seem like a browser issue. You have .nav set to display: inline-block; but nothing on the two inner <li> elements to force them onto the same line.
I added this:
.nav > li {
display: inline-block;
}
And it works for me in Chrome. See here:
https://jsfiddle.net/tobyl/wkupr9L6/6/
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.
My Html code:
<div id="wrapper">
<header id="header" role="banner">
<div id="logo">
<img src="Images/title.png" alt="logo" width="1018" height="140">
</div>
<div id="social">
<ul>
<li>
<img src="images/twitter.png" alt="Twitter" width="32" height="32">
</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>
<img src="images/youtube.png" alt="Youtube" width="32" height="32">
</li>
</ul>
</div>
<div id="clearfix">
</div>
<nav id="page_nav">
<div class="menu">
<ul id="navmenu">
<li class="active">Home</li>
<li>About Us</li>
<li>Get Involved<span class="darrow">▼</span>
<ul class="submenu">
<li>Social Media</li>
<li>Union Meetings</li>
<li>Rally</li>
</ul>
</li>
<li>News<span class="darrow">▼</span>
<ul class="submenu">
<li>Shrew's News</li>
<li>Update</li>
</ul>
</li>
<li>Gallery</li>
<li>Contact Us</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;
}
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">
<img src="Images/title.png" alt="logo" width="1018" height="140">
</div>
<div id="social">
<ul>
<li>
<img src="images/twitter.png" alt="Twitter" width="32" height="32">
</li>
<li>
<img src="images/facebook.png" alt="Facebook" width="32" height="32">
</li>
<li>
<img src="images/youtube.png" alt="Youtube" width="32" height="32">
</li>
</ul>
</div>
<div class="clearfix">
</div>
<nav id="page_nav">
<div class="menu">
<ul id="navmenu">
<li class="active">Home</li>
<li>About Us</li>
<li>
Get Involved<span class="darrow">▼</span>
<ul class="submenu">
<li>Social Media</li>
<li>Union Meetings</li>
<li>Rally</li>
</ul>
</li>
<li>
News<span class="darrow">▼</span>
<ul class="submenu">
<li>Shrew's News</li>
<li>Update</li>
</ul>
</li>
<li>Gallery</li>
<li>Contact Us</li>
</ul>
</div>
<div class="clearfix">
</div>
</nav>
</header>
</div>
I have whitespace between two html sections that I would like to get rid of. Here is a picture of it:
I removed any whitespace in my html code between /div and div, as suggested by answers from my searches, but it didn't seem to fix the problem.
HTML Code:
<!--website main heading layout-->
<div id="heading">
<h1> Beat Your Pace <h1/>
<h2> The music search tool to boost your running performance! </h2>
</div><div id="topbar">
<!--topbar/menu layout-->
<div id="topbar_wrapper">
<ul id="mainmenu">
<li>Home</li><li>
Search</li><li>
Sort By ▼
<ul id="sortmenu">
<li><a href='#'>Song</a>
<ul class="sortsubmenu">
<li><a href='#'>A to Z</a></li><li>
<a href='#'>Z to A</a></li>
</ul>
</li><li>
<a href='#'>Artist</a>
<ul class="sortsubmenu">
<li><a href='#'>A to Z</a></li><li>
<a href='#'>Z to A</a></li>
</ul>
</li><li>
<a href='#'>Album</a>
<ul class="sortsubmenu">
<li><a href='#'>A to Z</a></li><li>
<a href='#'>Z to A</a></li>
</ul>
</li><li>
<a href='#'>Genre</a>
<ul class="sortsubmenu">
<li><a href='#'>A to Z</a></li><li>
<a href='#'>Z to A</a></li>
</ul>
</li><li>
<a href='#'>BPM</a>
<ul class="sortsubmenu">
<li><a href='#'>Slowest to Fastest</a></li><li>
<a href='#'>Fastest to Slowest</a></li>
</ul>
</li><li>
<a href='#'>Release Date</a>
<ul class="sortsubmenu">
<li><a href='#'>Newest to Oldest</a></li><li>
<a href='#'>Oldest to Newest</a></li>
</ul>
</li>
</ul>
</li><li>
Add Song</li><li>
Contact Us</li>
</ul>
</div>
</div>
body and heading CSS Code:
html, body {
margin: 0px;
padding: 0px;
font-family: Arial;
font-size: 18px;
}
#heading {
background: url("http://cdn4.techlila.com/wp- content/uploads/2011/01/header2.jpg");
background-position: left;
color: black;
text-shadow: -1px 0 #F8F8FF, 0 1px #F8F8FF, 1px 0 #F8F8FF, 0 -1px #F8F8FF;
}
Menu CSS Code:
#topbar {
background-color: #222;
}
#topbar_wrapper {
width: 100%;
margin: 0 auto;
text-align: left;
}
#mainmenu {
list-style-type: none;
padding: 0px;
margin: 0px;
position: relative;
min-width: 200px;
}
#mainmenu > li {
display: inline-block;
width: 200px;
}
#mainmenu li:hover {
background-color: #333;
}
#mainmenu li a{
color: #CCC;
display: block;
padding: 15px;
text-decoration: none;
}
#mainmenu li:hover > ul {
display: block;
}
#sortmenu {
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-top: 0;
margin-left: -5px;
}
#sortmenu > li {
display: block;
position: relative;
}
#sortmenu li a:hover {
color: #699;
}
#sortmenu li: hover ul {
display: inline-block;
}
.sortsubmenu {
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-left: 0px;
text-align: right;
top: 0;
left: 100%;
width: auto;
}
.sortsubmenu li{
display: inline;
white-space: nowrap;
}
.sortsubmenu li a:hover {
color: #DB7093;
}
Remove the default on the <h2> element:
#heading h2 {
margin:0;
}
I am trying to get the gray buttons at the top of this page to all fit across the top (in line with the body), rather than on two lines: http://www.nbm.org/test/nbm-online-drafts/dropdown-testing.html
I have it set up as a list:
<nav id="main-nav">
<ul id="nav-primary">
<li><img src="http://www.nbm.org/assets/images/homepage/2011/nav-sprites/planyourvisit.jpg" alt="Plan Your Visit" width="109" height="48">
<ul class="subnav">
<li>Buy Tickets
</li>
<li>Hours & Admission
</li>
<li>Accessibility & Directions
</li>
<li>Tours
</li>
</ul>
</li>
<li><img src="http://www.nbm.org/assets/images/homepage/2011/nav-sprites/exhibitionscollections.jpg" alt="Exhibitions / Collections" width="109" height="48">
<ul class="subnav">
<li>Current Exhibitions
</li>
<li>Upcoming Exhibitions
</li>
<li>Buy Tickets
</li>
<li>Collections
</li>
</ul>
</li>
<li><img src=" http://www.nbm.org/assets/images/homepage/2011/nav-sprites/adultprogs.jpg" alt="Adult Programs" width="109" height="48">
<ul class="subnav">
<li>Upcoming Programs
</li>
<li>Spotlight on Design
</li>
<li>Watch / Listen
</li>
<li>Continuing Education Credits
</li>
</ul>
</li>
<li><img src="http://www.nbm.org/assets/images/homepage/2011/nav-sprites/familiesteens.jpg" alt="Families / Teens" width="109" height="48">
<ul class="subnav">
<li>Festivals
</li>
<li>Everyday Activities
</li>
<li>Teens & Young Adults
</li>
<li>Summer Camp
</li>
<li>Scouts & Youth Groups
</li>
<li>Birthday Parties
</li>
</ul>
</li>
<li><img src="http://www.nbm.org/assets/images/homepage/2011/nav-sprites/schoolseducators.jpg" alt="Schools / Educators" width="109" height="48">
<ul class="subnav">
<li>For Educators
</li>
<li>For Teens & Young Adults
</li>
<li>Plan a School Visit
</li>
</ul>
</li>
<li><img src="http://www.nbm.org/assets/images/homepage/2011/nav-sprites/joindonate.jpg" alt="Join / Donate" width="109" height="48">
<ul class="subnav">
<li>Donate Now
</li>
<li>Membership
</li>
<li>Corporate Giving
</li>
<li>Awards & Honors
</li>
<li>Volunteer
</li>
</ul>
</li>
<li><img src="http://www.nbm.org/assets/images/homepage/2011/nav-sprites/shop.jpg" alt="Shop" width="109" height="48">
<ul class="subnav">
<li>Books
</li>
<li>Home
</li>
<li>Toys
</li>
<li>Museum
</li>
<li>Stationery
</li>
<li>Fashion
</li>
<li>Design
</li>
</ul>
</li>
<li><img src="http://www.nbm.org/assets/images/homepage/2011/nav-sprites/aboutus.jpg" alt="About Us" width="109" height="48">
<ul class="subnav">
<li>About the Museum
</li>
<li>E-newsletters
</li>
<li>Press Room
</li>
<li>Staff & Governance
</li>
<li>Employment & Internships
</li>
</ul>
</li>
</ul>
I want to keep the li right margin at 4px, but that pushes the "About Us" button to a second line. Changing the li right margin to 3px is too little and the buttons do not line up with the body on the right.
CSS:
#main-nav {
background: none repeat scroll 0 0 white;
height: 53px;
left: 0;
position: relative;
top: 128px;
width: 100%;
z-index: 11;
}
#main-nav .subnav {
background: none repeat scroll 0 0 #D7D6D4;
border: 0 solid #D4D5D6;
display: none;
left: 0;
list-style-type: none;
margin: 0;
padding: 0;
position: absolute;
top: 49px;
width: 109px;
z-index: 11;
}
#main-nav .subnav li {
border-bottom: 1px solid #EEEEEE;
display: block;
margin: 0;
}
#main-nav .subnav li a {
color: #000000;
font-size: 11px;
height: 18px;
padding: 6px 4px 19px;
width: 101px;
}
#main-nav .subnav li a:hover {
background: none repeat scroll 0 0 #BFBEBA;
width: 101px;
}
#nav-primary {
float: left;
list-style-type: none;
margin: 0;
padding: 0;
}
#nav-primary li {
float: left;
margin-right: 4px;
position: relative;
}
#nav-primary li a {
color: #000000;
float: left;
font-size: 13px;
font-weight: bold;
height: 48px;
line-height: 16px;
text-align: center;
text-decoration: none;
width: 109px;
}
#nav-primary li a:hover {
text-decoration: none;
}
#nav-primary li:hover .subnav {
display: block;
}
Is it possible to remove the right margin on the last li element? Or to hide it?
Any ideas are much appreciated!
It is this simple:
#nav-primary > li:last-child
{
margin-right:0;
}