Stylizing Horizontal Navigation Bar - html

I'm creating a horizontal navigation bar and would like to stylize it so that a thin line will appear right above the bar (please see example).
Nav Bar Example
As you can see there is a thin, gold line just above the red navigation bar. I would like to get a thin, black line just above my orange navigation bar.
My code looks like this:
(CSS)
nav {width:100%;display:block;}
nav ul {list-style-type:none;margin:0;padding:0;text-align:center;background-color:#c0872e}
nav li {display:inline-block;background-color:#c0872e;}
nav a {line-height:35px; color:white; padding:0 30px; font-size:22px; font-family:WindsorDemi.fog Cn; background-color:#c0872e;}
nav a:hover {text-decoration:none}
(HTML)
<div>
<ul>
<li>Home</li>
<li>Products</li>
</ul>
</div>
Please let me know how I can achieve this desired effect. Thank you!

You could accomplish this using a border:
nav ul {
border-top: 2px solid #000; /* Added */
list-style-type:none;
margin:0;
padding:0;
text-align:center;
background-color:#c0872e
}
Here's a JSFiddle to show you how it looks.
Hope this helps! Let me know if you have any questions.

Just do this (add border-top)
CSS
nav ul {
list-style-type:none;
margin:0;padding:0;
text-align:center;
background-color:#c0872e;
border-top: solid 1px #000; // Add this (adjust your needs)
}

First, we need to change your surrounding div to the nav element.
<nav>
<ul>
<li>Home</li>
<li>Products</li>
</ul>
</nav>
Then just add a border-top to the nav css.
nav {width:100%;display:block;border-top:4px solid #000;}
nav ul {list-style-type:none;margin:0;padding:0;text-align:center;background-color:#c0872e}
nav li {display:inline-block;background-color:#c0872e;}
nav a {line-height:35px; color:white; padding:0 30px; font-size:22px; font-family:WindsorDemi.fog Cn; background-color:#c0872e;}
nav a:hover {text-decoration:none}

Related

I have a few css issues with a dropdown menu I've created

I get the feeling that these are really simple problems, however I'm new to coding and can't work out how to fix them. Any help would be greatly appreciated.
Firstly, the hyperlink text is currently the only clickable part of the dropdown menu. I want to be able to click the whole section of the menu that the text sits in, i.e the individual parts separated by the 1px borders. I'd also like these sections to change color when the cursor hovers over them, but I'm not sure which part of the css to change if I want to achieve this.
Secondly, the padding creating the space between my main menu links is being included in the link hover function. Is there a way of spacing out the links that doesn't cause the subpages to drop down when I hover over the white space to the left of them? (This seems like the opposite of my first problem)
Finally, part of the css I've written makes any of the parent menu links that have been clicked stay highlighted purple while the viewer is on that page. This was intentional, however now that I have child pages in the dropdown menu, they all stay that color too when the parent page is clicked. Is there a way of fixing this? it would be ideal if both the parent link and the specific child link stayed highlighted purple whilst the viewer was on a that particular child page.
The website link is www.lucieaverill.co.uk
Here is the code :
HTML:
<nav class="site-nav">
<?php $args = array('theme_location' => 'primary'); ?>
<?php wp_nav_menu(); ?>
</nav>
CSS:
/* header navigation menu */
.header nav ul{
display:block;
float:right;
width:auto;
margin-top:15px;
padding: 0;
background-color:#ffffff;
list-style:none;
}
.header nav ul li {
float:left;
padding-left:50px;
padding-bottom:20px;
}
.header nav ul li.current-menu-item a:link,
.header nav ul li.current-menu-item a:visited{
color:#A084BD;
}
/* dropdown menu */
.header nav ul ul {
position:absolute;
left: -999em;
}
.header ul li:hover ul {
left:auto;
width: 200px;
}
.header ul li ul li {
float:none;
padding-left:10px;
padding-top: 12px;
padding-bottom: 12px;
border-bottom: 1px solid #ededed;
}
.header ul li ul li a {
font-size:11px;}
/* end dropdown menu */
/* end header navigation menu */
UPDATE! ------------------------------
I think I've made some progress based on what various people have been saying about a tags. I've managed to reach the point where the hover effect changes the a tag's color, however the padding is a little off, and I can't work out why. I've tried setting the padding-right value to "auto", as I don't think it can have a specific value as each link varies in length.
Obviously, I want the padding to extend to the very end of the menu at the right hand side, but I can't make this work.
There also seems to be some odd spacing between the color of each link, and at the very bottom of the menu.
I'm surprised to see that the transition between colors is smooth and gradual.. I don't think I have any css that tells it to act like this.. is there a way of making it more instant?
The web link again, is www.lucieaverill.co.uk
/* dropdown menu */
.header nav ul ul {
position:absolute;
left: -999em;
}
.header ul li:hover ul {
left:auto;
width: 200px;
}
.header ul li ul li {
margin-left:0px;
float:none;
}
.header ul li ul li a {
background-color:#FF3F55;
padding-left:10px;
padding-right:auto;
padding-top: 12px;
padding-bottom: 12px;
font-size:11px;
border-bottom: 1px solid #ededed;
}
.header ul li ul li:hover a {
background-color:#ededed; }
/* end dropdown menu */
See the fiddle:
Remove the padding of li and add the required padding to a tag.
the clickable problem will be fixed.
/* header navigation menu */
.header nav ul{
display:block;
float:right;
width:auto;
margin-top:15px;
padding: 0;
background-color:#ffffff;
list-style:none;
}
.header nav ul li {
float:left;
padding:0px;
}
.header nav ul li a{
padding:20px 25px;
}
.header nav ul li a:hover {
color:white;
background:black;
}
.header nav ul li.current-menu-item a:link,
.header nav ul li.current-menu-item a:visited{
color:#A084BD;
}
/* dropdown menu */
.header nav ul ul {
position:absolute;
left: -999em;
}
.header ul li:hover ul {
left:auto;
width: 200px;
}
.header ul li ul li {
float:none;
padding-left:10px;
padding-top: 12px;
padding-bottom: 12px;
border-bottom: 1px solid #ededed;
}
.header ul li ul li a {
font-size:11px;}
/* end dropdown menu */
/* end header navigation menu */
<div class="header">
<nav class="site-nav">
<ul>
<li>menu1</li>
<li>menu2</li>
<li>submenu
<ul>
<li>submenu1</li>
<li>submenu2</li>
</ul>
</li>
</ul>
</nav>
</div>

Navbar Menu Trouble shoot

So I wanted to create the fixed nav bar on top of the page. Instead of creating nav bar with ordered list, I used the following approach:
<header>
<div class="nav">
<img src="images/logo_ab.png" alt="AurinBioTech Logo"/>
Home
About
Team
Science
Need
Pipeline
Contact
</div>
</header>
CSS:
header .nav {
margin-top:100px;
width:100%;
height:10%;
text-align:center;
padding-top:2%;
margin:0 auto;
position:fixed;
top:0;
}
header .nav a {
font-size: 2em;
padding-left: 15px;
padding-right: 15px;
color:rgb(1, 1, 1);
text-decoration: none;
font-family: 'Bebas';
}
header .nav a:hover {
color:white;
background-color: #404040;
border-radius:5px;
padding:0 auto;
}
header .nav a:active{
background-color: #404040;
border-radius:5px;
text-decoration:overline;
}
header .nav img {
width:260px;
height:65px;
padding-right:4em;
}
The reason I used this approach is because I wanted to use logo image next to the nav bar so it would align properly in the same line. Now the problem is that I need to add sub-menus under Science and Pipeline heading. Since I didn't use UL or LI, how can I add sub-menus under those heading.
OR, can you tell me any other way to create a NAV bar that shows the logo as well.
so it would be LOGO and MENUS on the same line.
Great thanks in advance.
Use the normal ul li structure.
If you set the height and line-height of top level li tags to be equal to the height of the image it will align the text to the center of the image.
I can suggest you to use a tool.
CSSMENU where you can create a menu without writing the code.You can also change the code or add images as your wish if needed. There are some inbuilt images where you can use them too.
have a two column structure in your nav bar one column for the logo and other for the nav-bar options.
<header>
<div class="nav">
<img src="images/logo_ab.png" alt="AurinBioTech Logo"/>
</div>
<div class="options">
<ul>
<li>Home</li>
<li>About</li>
<li>Team</li>
<li>Science</li>
<li>Need</li>
<li>Pipeline</li>
<li>Contact</li>
</ul>
</div>
</header>
and
with css give them appropriate width and align them using padding or margin properties

Left side border is not displaying on menubar

I have created CSS menu bar for my webpage. But Left side border is not displaying when some one move mouse on "My Presentations" link. Currently "My Favorite" link is selected. Please notice Left side gray border is not displaying on "My Favorite" link. But when u move mouse on "Friend's Favorite" link then right side border in displaying on "My Favorite" link. I need to display left side border to.
Here is the link:-
jsFiddle Link
<ul class="menu" style="margin-top:20px;">
<li>Home</li>
<li>My Presentations</li>
<li class="current">My Favorite</li>
<li>Friend's Favorite</li>
<li>Most Viewed</li>
<li>Sync account</li>
</ul>
/* NAVBAR CSS START HERE */
.menu,.menu ul,.menu li,.menu a {margin: 0;padding: 0;border: none;outline: none;}
.menu {height: 30px;width: 759px;background: #3B5998;border:1px solid #e1e1e1; border-top-left-radius:5px;-moz-border-radius-topleft:5px; border-top-right-radius:5px;-moz-border-radius-topright:5px}
.menu li {position: relative;list-style: none;float: left;display: block;height: 30px;}
.menu ul { display: none;}
.menu li a{display: block;padding: 0 14px;line-height: 30px;text-decoration: none;font-family: Tahoma;font-weight: bold;font-size: 11px;color: #f9f9f9;border-left:1px solid #8698C0;}
.menu li:hover > a{ color: #9a9a9a; background:#fff; border-left:1px solid #ccc;}
.menu li a.first{border-left:0px; background:#ffvv00;}
.menu li.current a{border:0px; height:31px;color: #9a9a9a; background:#fff; margin-top:-3px; padding-top:3px; padding-bottom:4px;border-top-left-radius:5px;-moz-border-radius-topleft:5px; border-top-right-radius:5px;-moz-border-radius-topright:5px;}
.menu li:first-child a:hover{border-top-left-radius:5px;-moz-border-radius-topleft:5px; border-right:1px #ccc solid; margin-right:-1px;}
.menu li:last-child a{border-right: none; }
Did many changes to the code, it better to take look at the demo
New Demo
Note :
I am not sure, why you made your active element more taller than other elements, and they have some rounded edge. It looks odd

How do I make a horizontal navbar using CSS, that supports hover and respects the edges of the container?

I am trying to make a CSS based nav bar that converts a UL/LI list (including sub UL/LI lists that display on hover) into a horizontal nav bar and a sub horizontal nav bar. My current implementation (see picture) works except the sub list is using position:absolute to get its position below the hovered element. I believe that is the source of my problem, as the absolute positioned sub menu doesnt respect the edges of the container, so if the browser gets too small it bleeds off the edge of the container while the top level menu wraps. The other problem i'm having is that it doesnt expand the page vertically when the top level menu wraps, so even though its taking up more space the paragraph following doesnt move down and gets overlapped.
Does anybody have any CSS tips or know of any good examples of a menu like the one I'm trying to make?
Link to image:
http://i47.tinypic.com/288tbn7.png
To this day, the article "Son of Suckerfish Dropdowns" by HTML Dog is still a classic on clean CSS menus with hover.
http://www.htmldog.com/articles/suckerfish/dropdowns/
Hey now create this menu easily used to ul li simply as like this
HTML
<ul class="menu">
<li>Home</li>
<li>Home2</li>
<li>Home3
<ul class="submenu">
<li>Submenu</li>
<li>Submenu</li>
<li>Submenu</li>
</ul>
</li>
<li>Home4</li>
<li>Home5</li>
</ul>
Css
.menu{
display:block;
list-style:none;
border-bottom:solid 1px red;
float:left;
}
.menu > li{
float:left;
position:relative;
}
.menu > li + li{
border-left:solid 1px red;
margin-left:10px;
}
.menu > li > a{
display:block;
margin-left:10px;
}
.submenu{
display:none;
list-style:none;
position:absolute;
top:20px;
left:-39px;
white-space:nowrap;
}
.menu > li:hover .submenu{
display:block;
}
.submenu li{
display:inline;
}
.submenu li + li {
border-left:1px solid green;
margin-left:10px;
}
.submenu a{
display:inline-block;
vertical-align:top;
margin-left:10px;
}
Live demo
and now change css according to your layout this is basic step

help converting a normal nav bar to a drop down nav bar

I hav a simple nav bar that i want to convert into a drop down nav bar, but i am not sure what i have to do to accomplish this. Do i need a certain javascript code or css. thanks
/* navigation menu */
div#navigation {
height:55px;
background:#0C1C29 url('images/nav-bg.png') repeat-x scroll top left;
}
div#innernav {
background:transparent url('images/nav-left.png') no-repeat scroll top left;
height:55px;
}
div#navigation ul {
background:transparent url('images/nav-right.png') no-repeat scroll top right;
list-style:none;
margin:0;
padding:0 10px;
position:relative;
top:0;
height:55px;
display:block;
}
div#navigation ul li {
display:block;
float:left;
}
div#navigation ul li a {
display:block;
float:left;
color:#ffffff;
border-bottom:none;
height:32px;
font-family:"Trebuchet MS", Verdana, Arial;
font-weight:bold;
font-size:1.2em;
padding:14px 20px 9px;
border-right:1px solid #060D14;
border-left:1px solid #244566;
}
div#navigation ul li.navleft a {
border-left:none;
}
div#navigation ul li.navright a {
border-right:none;
}
div#navigation ul li a:hover {
color:#FC8228;
}
<div id="navigation">
<div id="innernav">
<ul>
<!-- top navigation -->
<!-- add class navleft to first item and navright to last item as shown -->
<li class="navleft">home</li>
<li>examples</li>
<li>solutions</li>
<li>our service</li>
<li>support</li>
<li class="navright">contact</li>
</ul>
</div>
</div>
Here is an example that uses the suckerfish methodology:
http://jsfiddle.net/uCdGc/
Here is the magic CSS:
/* Code for dropdown */
#navigation ul li ul {
position: absolute;
left:-999em;
}
#navigation ul li ul li {
float:none;
/* put the rest of your styles here*/
}
#navigation ul li:hover ul, #navigation ul li.sfhover ul {
left:auto;
margin-top:55px;
}
For more on suckerfish, check out this url: http://www.htmldog.com/articles/suckerfish/dropdowns/
What I've done is added a ul element containing subnavigation elements to your "Examples" navigation item. When you hover over, the CSS will position the subnavigation so that it appears where you want it. This should work without any javascript, but if you want to support IE 6, you will need to include the jQuery javascript library and the code in the javascript block in the example.
Right now the subnavigation is styled plainly, but add more styles as you need. I've commented where you should add them.
Good luck.