Interesting title I know, didn't know how else to word it. I'm trying to have my navigation bar items evenly spaced regardless of font type which will change the size slightly. I've included a :hover feature with will darken the background behind the items. This works well, however when I add margins or padding to the left and right of nav ul to indent the sides, the darkened area is omitted from the margin/padding space.
The first is how it looks with no 'nav ul' padding. The second is with it where the area is cut off and the third is how I'd like it to look (with the 'home' text more centered, this was a rough mspaint edit lol.
On top of this, is there a way to make the padding for the 'header nav ul li a {' align perfectly so there's no space inbetween? I have a few px's space between where the hover occurs to allow for change in font-type without ruining the even spacing.
Totally a beginner at both CSS and HTML so if you're going to help me please only offer your kindest beginner-friendly advice.
JSFiddle: https://jsfiddle.net/c1y9axqt/
Relevant code:
CSS
.container {
width: 960px;
padding: 0 10px;
margin: 0 auto;
}
.nav_menu {
background-color: #005073;
background-image: -webkit-linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* For Safari 5.1 to 6.0 */
background-image: -o-linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* For Opera 11.1 to 12.0 */
background-image: -moz-linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* For Firefox 3.6 to 15 */
background-image: linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* Standard syntax */
-webkit-box-shadow: inset 0px 0px 2px 1px rgba(0,0,0,0.4); /* For Firefox 3.6 to 15 */
-moz-box-shadow: inset 0px 0px 2px 1px rgba(0,0,0,0.4); /* For Firefox 3.6 to 15 */
box-shadow: inset 0px 0px 2px 1x rgba(0,0,0,0.4); /* Standard syntax */
border-style: solid;
border-width: 1px;
border-color: black;
height: 26px;
}
nav ul {
margin: 0;
padding: 0;
display: flex;
justify-content:space-between;
}
nav ul li{
display: inline;
}
header nav ul li a {
display: inline;
padding: 6px 30px 6px 30px;
letter-spacing: 1px;
text-decoration: none;
font-weight: bold;
line-height: 26px;
color: #EBEAEA;
text-shadow:
-1px -1px 1px rgba(0, 0, 0, .6),
1px -1px 1px rgba(0, 0, 0, .6),
-1px 1px 1px rgba(0, 0, 0, .6),
1px 1px 1px rgba(0, 0, 0, .6);
}
header nav ul li a:hover {
color: #E1E0E0;
background: rgba(0,0,0,0.2);
}
header nav ul li a:active {
-webkit-box-shadow: 0 0 5px rgba(0,0,0,0.7) inset;
-moz-box-shadow: 0 0 5px rgba(0,0,0,0.7) inset;
box-shadow: 0 0 5px rgba(0,0,0,0.7) inset;
color: #CECCCC;
background: rgba(0,0,0,0.3);
}
HTML
<header>
<div class="container clearfix">
<div class="nav_menu">
<nav>
<ul>
<li>Home</li>
<li>Website Design</li>
<li>Art & Poetry</li>
<li>Blog & Other</li>
<li>Music & More</li>
<li>Shop</li>
</ul>
</nav>
</div> <!-- end of container-->
</div> <!-- end of navigator menu bar-->
</header>
JSFiddle (again lol): https://jsfiddle.net/c1y9axqt/
guess you wanted this i changed only the css thats all
.container {
width: 960px;
padding: 0 10px;
margin: 0 auto;
}
.nav_menu {
background-color: #005073;
background-image: -webkit-linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* For Safari 5.1 to 6.0 */
background-image: -o-linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* For Opera 11.1 to 12.0 */
background-image: -moz-linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* For Firefox 3.6 to 15 */
background-image: linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* Standard syntax */
-webkit-box-shadow: inset 0px 0px 2px 1px rgba(0,0,0,0.4); /* For Firefox 3.6 to 15 */
-moz-box-shadow: inset 0px 0px 2px 1px rgba(0,0,0,0.4); /* For Firefox 3.6 to 15 */
box-shadow: inset 0px 0px 2px 1x rgba(0,0,0,0.4); /* Standard syntax */
border-style: solid;
border-width: 1px;
border-color: black;
height: 26px;
}
header nav ul li:hover {
color: #E1E0E0;
background: rgba(0,0,0,0.2);
}
nav ul {
margin: 0;
padding: 0;
display: flex;
justify-content:space-between;
}
nav ul li{
display: inline;
width:160px;
text-align:center;
}
header nav ul li a {
display: inline;
letter-spacing: 1px;
text-decoration: none;
font-weight: bold;
line-height: 26px;
color: #EBEAEA;
text-shadow:
-1px -1px 1px rgba(0, 0, 0, .6),
1px -1px 1px rgba(0, 0, 0, .6),
-1px 1px 1px rgba(0, 0, 0, .6),
1px 1px 1px rgba(0, 0, 0, .6);
}
header nav ul li a:hover {
color: #E1E0E0;
background: rgba(0,0,0,0.2);
}
header nav ul li a:active {
-webkit-box-shadow: 0 0 5px rgba(0,0,0,0.7) inset;
-moz-box-shadow: 0 0 5px rgba(0,0,0,0.7) inset;
box-shadow: 0 0 5px rgba(0,0,0,0.7) inset;
color: #CECCCC;
background: rgba(0,0,0,0.3);
}
hope it helps
I've changed the way you had it styled slightly to keep things in blocks. I think you'd over complicated it for yourself in places.
As you can see i've set a width on the list items in the nav using % to keep them all evenly sized, and given them text-align: center;. Then by setting the background color of the anchor tags, it makes changing the color for the hover effect much easier.
You should look into Media Queries to make the nav become responsive for smaller screens.
Hope this all help,
Happy Coding!
Fiddle here
HTML:
<div id="navContainer">
<nav>
<ul>
<li>Home</li>
<li>Website Design</li>
<li>Art & Poetry</li>
<li>Blog & Other</li>
<li>Music & More</li>
<li>Shop</li>
</ul>
</nav>
</div>
CSS:
body {
margin: 0px 0px;
}
#navContainer {
width: 100%;
}
#navContainer nav {
width: 960px;
margin-left: auto;
margin-right: auto;
}
#navContainer ul {
list-style: none;
list-style-type: none;
padding: 0px 0px;
margin: 0px 0px;
}
#navContainer li {
float: left;
width: 16.666667%;
text-align: center;
}
#navContainer a {
text-decoration: none;
display: block;
background-color: #005073;
line-height: 26px;
}
#navContainer a {
text-decoration: none;
display: block;
background-color: #005073;
line-height: 26px;
color: #EBEAEA;
text-shadow:
-1px -1px 1px rgba(0, 0, 0, .6),
1px -1px 1px rgba(0, 0, 0, .6),
-1px 1px 1px rgba(0, 0, 0, .6),
1px 1px 1px rgba(0, 0, 0, .6);
font-weight: bold;
letter-spacing: 1px;
background-image: -webkit-linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* For Safari 5.1 to 6.0 */
background-image: -o-linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* For Opera 11.1 to 12.0 */
background-image: -moz-linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* For Firefox 3.6 to 15 */
background-image: linear-gradient(rgba(0,0,0,.3), rgba(125,125,125,.3)); /* Standard syntax */
}
#navContainer a:hover {
color: #E1E0E0;
background-image: -webkit-linear-gradient(rgba(0,0,0,.3), rgba(0,0,0,.2)); /* For Safari 5.1 to 6.0 */
background-image: -o-linear-gradient(rgba(0,0,0,.3), rgba(0,0,0,.2)); /* For Opera 11.1 to 12.0 */
background-image: -moz-linear-gradient(rgba(0,0,0,.3), rgba(0,0,0,.2)); /* For Firefox 3.6 to 15 */
background-image: linear-gradient(rgba(0,0,0,.3), rgba(0,0,0,.2)); /* Standard syntax */
}
I have an upper menu with the following CSS:-
nav {
background: -webkit-gradient(linear, center top, center bottom, from(#fff), to(#ccc));
background-image: linear-gradient(#fff, #ccc);
border-radius: 6px;
box-shadow: 0px 0px 4px 2px rgba(0,0,0,0.4);
padding: 0 10px;
position: relative;
}
.menu li {
float: left;
position: relative;
list-style-type: none;
/*background: url('img/denim.png');
font-family: 'Droid Sans', sans-serif;*/
}
.menu li a {
color: #444;
display: block;
font-size: 12px;
line-height: 5px;
padding: 6px 12px;
margin: 8px 8px;
vertical-align: middle;
text-decoration: none;
}
.menu li a:hover {
background: -webkit-gradient(linear, center top, center bottom, from(#ededed), to(#fff));
background-image: linear-gradient(#ededed, #fff);
border-radius: 12px;
box-shadow: inset 0px 0px 1px 1px rgba(0,0,0,0.1);
color: #222;
}
/* Dropdown styles */
.menu ul {
position: absolute;
left: -9999px;
list-style: none;
opacity: 0;
transition: opacity 1s ease;
}
.menu ul li {
float: none;
}
.menu ul a {
white-space: nowrap;
}
/* Displays the dropdown on hover and moves back into position */
.menu li:hover ul {
background: rgba(255,255,255,0.7);
border-radius: 0 0 6px 6px;
box-shadow: inset 0px 2px 4px rgba(0,0,0,0.4);
left: 5px;
opacity: 1;
}
/* Persistant Hover State */
.menu li:hover a {
background: -webkit-gradient(linear, center top, center bottom, from(#ccc), to(#ededed));
background-image: linear-gradient(#ccc, #ededed);
border-radius: 12px;
box-shadow: inset 0px 0px 1px 1px rgba(0,0,0,0.1);
color: #222;
}
.menu li:hover ul a {
background: none;
border-radius: 0;
box-shadow: none;
}
.menu li:hover ul li a:hover {
background: -webkit-gradient(linear, center top, center bottom, from(#eee), to(#fff));
background-image: linear-gradient(#ededed, #fff);
border-radius: 12px;
box-shadow: inset 0px 0px 4px 2px rgba(0,0,0,0.3);
}
Currently when the menu is displayed above an icon , the icon will occur above the menu text as follow:-
So is there a way to force the menu to be displayed above any text and icons ?
Thanks
Use Z-index to a high level on the menu and set the background color to solid white on the .menu li class as shown below:
nav {
background: -webkit-gradient(linear, center top, center bottom, from(#fff), to(#ccc));
background-image: linear-gradient(#fff, #ccc);
border-radius: 6px;
box-shadow: 0px 0px 4px 2px rgba(0,0,0,0.4);
padding: 0 10px;
position: relative;
z-index: 1000;
}
.menu li {
float: left;
position: relative;
list-style-type: none;
/*background: url('img/denim.png');
font-family: 'Droid Sans', sans-serif;*/
z-index: 1000;
}
.menu li:hover ul {
/*background: rgba(255,255,255,0.7);*/
background: rgba(255,255,255,1); /* use this to make the background solid white */
border-radius: 0 0 6px 6px;
box-shadow: inset 0px 2px 4px rgba(0,0,0,0.4);
left: 5px;
opacity: 1;
z-index:1000;
}
You need to change the background-color opacity to 1 block out the rear elements.
.menu li:hover ul {
background: rgba(255,255,255,1);
...
I was working on web project, then a requirement came that I should add a top-level menu to my site. So I did a search and I found a menu from this URL http://www.webdesignerdepot.com/2012/08/create-a-stunning-menu-in-css3/.
But when I added the required css files & font, then menu was displayed out of the layout as follow:-
So can anyone advise on how I can do the following :-
To expand the menu horizontally to cover the whole screen .as for the top blue-colored area.
to have it exeactly below the blue-colored top area.
Reduce the menu width, and have it same as the breadcrumb.
Thanks
the css for the menu is :-
.clearfix {
clear: both;
}
.wrap {
width: 940px;
margin: 4em auto;
}
nav {
background: -webkit-gradient(linear, center top, center bottom, from(#fff), to(#ccc));
background-image: linear-gradient(#fff, #ccc);
border-radius: 6px;
box-shadow: 0px 0px 4px 2px rgba(0,0,0,0.4);
padding: 0 10px;
position: relative;
}
.menu li {
float: left;
position: relative;
}
.menu li a {
color: #444;
display: block;
font-size: 14px;
line-height: 20px;
padding: 6px 12px;
margin: 8px 8px;
vertical-align: middle;
text-decoration: none;
}
.menu li a:hover {
background: -webkit-gradient(linear, center top, center bottom, from(#ededed), to(#fff));
background-image: linear-gradient(#ededed, #fff);
border-radius: 12px;
box-shadow: inset 0px 0px 1px 1px rgba(0,0,0,0.1);
color: #222;
}
/* Dropdown styles */
.menu ul {
position: absolute;
left: -9999px;
list-style: none;
opacity: 0;
transition: opacity 1s ease;
}
.menu ul li {
float: none;
}
.menu ul a {
white-space: nowrap;
}
/* Displays the dropdown on hover and moves back into position */
.menu li:hover ul {
background: rgba(255,255,255,0.7);
border-radius: 0 0 6px 6px;
box-shadow: inset 0px 2px 4px rgba(0,0,0,0.4);
left: 5px;
opacity: 1;
}
/* Persistant Hover State */
.menu li:hover a {
background: -webkit-gradient(linear, center top, center bottom, from(#ccc), to(#ededed));
background-image: linear-gradient(#ccc, #ededed);
border-radius: 12px;
box-shadow: inset 0px 0px 1px 1px rgba(0,0,0,0.1);
color: #222;
}
.menu li:hover ul a {
background: none;
border-radius: 0;
box-shadow: none;
}
.menu li:hover ul li a:hover {
background: -webkit-gradient(linear, center top, center bottom, from(#eee), to(#fff));
background-image: linear-gradient(#ededed, #fff);
border-radius: 12px;
box-shadow: inset 0px 0px 4px 2px rgba(0,0,0,0.3);
}
#font-face {
font-family: 'IconicStroke';
src: url("~/fonts/iconic/iconic_stroke.eot");
src: local('IconicStroke'),
url("~/fonts/iconic/iconic_stroke.svg#iconic") format('svg'),
url("~/fonts/iconic/iconic_stroke.otf") format('opentype');
}
.iconic {
color:inherit;
font-family: "IconicStroke";
font-size: 38px;
line-height: 20px;
vertical-align: middle;
}
a.iconic:hover {
color:inherit;
}
My advice! Use firebug(an addon of firefox). Click on the menu and it will open all the css. Try changing them dynamically and chk the changes instantly. It even gives you the file where you need to make changes.
Apart from that what john said is right. Using fluid layout(%) is better than rigid(px). So when you say you need Menu to be of size of page then just make it 100%.
Happy Coding!
I am trying to get different 's to look differently, depending on the context. For example, in my html I have
<li> Home </li>
<li> Types of Insurance </li>
<li> Insurance Basics </li>
<li> Customer Center </li>
<li> About </li>
and in my css I have
.navlink : link
{
display:block;
width:120px;
text-align:center;
padding:10px;
text-decoration:none;
color:#FFFFFF;
}
.navlink : hover
{
background-color:#ADD8E6;
}
.navlink : visited
{
background-color:#ADD8E6;
}
But this is not working (the links appear unstylized). How would I fix this?
There must be no space before or after the :.
You need to get rid of the space before and after the colon (:).
You can also minimize your code by doing this:
.navlink {
// styling for unclicked link
}
.navlink:hover, .navlink:visited {
// styling for hover/visited state
}
I'm combining hover and visited because the only change you've made is the color, and it's the same for both.
Demo.
#nav{
float: left;
display: block;
font-size: 16px;
/*font-weight: bold;*/
font-family: 'Georgia', serif;
}
#nav>li{
display: block;
float: left;
line-height: 36px;
padding-right: 10px;
margin-left: 3px;
margin-right: 3px;
background: url(../img/nav-bullet.png) no-repeat center right;
}
#nav li>a:first-letter {
font-family: 'YataghanRegular', 'Georgia', serif;
font-size: 20px;
}
#nav li>a{ /* Parent Menu without hover*/
text-decoration: none;
color: #000000;
/*color: #CC3700; 606060*/
padding: 0px 10px 0px 10px;
display: block;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
#nav li:last-child{
background: none;
}
#nav>li:hover>a,
#nav>li.current-menu-item>a{/* Parent menu color with hover */
/*color: #eee;
background: #363636;*/
color:#000000;
background: #cce4ff ;
/*font-size: 12px;*/
/*background: -webkit-gradient(linear, left top, left bottom, from(#000000), to(#353535));
background: -moz-linear-gradient(top, #000000, #353535);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#353535', GradientType=0);*/
/*text-shadow: 0 -1px rgba(0, 0, 0, 0.7);*/
-webkit-box-shadow: 0px 1px 2px rgba(0,0,0,.5);
-moz-box-shadow: 0px 1px 2px rgba(0,0,0,.5);
box-shadow: 0px 1px 2px rgba(0,0,0,.5);
}
Try This..
Within an html file I have a menu set up as:
<div id="informheader" class="topmenu">
<ul id="navigationMenu">
<li>Home</li>
<li>Reporting</li>
<li>Dashboard</li>
<li>My Profile</li>
<li>Management Console</li>
</ul>
</div>
Within the CSS
.topmenu ul a
{
line-height:36px;
text-decoration: none;
color: #ffffff;
display:inline-block;
padding: 0px 5px 0px 5px;
background-position: 100%;
}
.topmenu li a:hover
{
background-image: url('../images/gradientheaderdark.png');
height: 36px;
display: inline-block;
text-decoration: none;
background-repeat: repeat-x;
margin-top:-5px;
line-height:36px;
}
.topmenu
{
position: relative;
display: block;
width: 80%;
height: 36px;
margin: 5px auto;
text-align: left;
z-index: 9998;
-khtml-border-radius: 4px;
-ms-border-radius: 4px;
-o-border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
-khtml-box-shadow: rgba(0,0,0,0.3) 0 1px 2px;
-ms-box-shadow: rgba(0,0,0,0.3) 0 1px 2px;
-o-box-shadow: rgba(0,0,0,0.3) 0 1px 2px;
-moz-box-shadow: rgba(0,0,0,0.3) 0 1px 2px;
-webkit-box-shadow: rgba(0,0,0,0.3) 0 1px 2px;
box-shadow: rgba(0,0,0,0.3) 0 1px 2px;
background-image: url('../images/gradientheader.png');
background-repeat: repeat-x;
}
.topmenu ul
{
display:inline-block;
list-style-type: none;
padding: 0;
margin: auto 0;
}
.topmenu li
{
display: inline-block;
list-style:none;
padding: 0px 5px 0px 5px;
}
The result renders the bullet-ed list horizontally in IE fine. However in Firefox the list stays vertical. Can anyone point me in the correct direction as to what tag I am missing to get Firefox to also render this UL list horizontally in Firefox (as well as safari)?
Switching the display to block vs inline-block flips the issue for IE.
Add float: left; to .topmenu li