I'm trying to create an overline effect on hover with css. What I have so far is below. Here's the problem I have, the over line appears directly above the text. I want there to be some space b/w them. Here is my site: http://baycity2014.weebly.com, and here's the effect I'm going for: http://www.hartlevin.com. Any advice?
CSS:
#nav-wrap .container {
clear: both;
overflow: hidden;
position: relative;
}
#nav-wrap .container {
/*background:url(nav-bg-medium.jpg) repeat-x top;*/
/*height:45px;*/
}
#nav-wrap .container ul {
list-style: none;
}
#nav-wrap .container ul li {
list-style: none;
float: left;
/* background:url(nav-saperator-medium.jpg) no-repeat right;*/
padding-right:2px;
}
#nav-wrap .container ul > li:first-child a,
#nav-wrap .container ul > li:first-child a:hover,
#nav-wrap .container ul span:first-child li a,
#nav-wrap .container ul span:first-child li a:hover{
border-radius:5px 0px 0px 5px;
}
#nav-wrap .container ul li a {
float: left;
display: block;
font-family: 'Helvetica', san-serif;
color: #000;
padding: 0px 30px;
border: 0px solid;
outline: 0;
list-style-type: none;
font-size: 16px;
line-height:45px;
/*text-shadow: 0px -1px 0px #333333;*/
}
#nav-wrap .container ul li:hover {
/*background:url(nav-saperator-hover-medium.jpg) no-repeat right;*/
}
#nav-wrap .container ul li a:hover {
/*background:url(nav-bg-hover-medium.jpg) repeat-x top ;*/
color: #145D85;
text-decoration:overline;
}
HTML:
<div id="left_content_nav">
<ul class='wsite-menu-default'>
<li id='active'><a href='/'>Home</a>
</li>
<li id='pg886612977153583720'><a href='/about.html'>About</a>
<div class='wsite-menu-wrap' style='display:none'>
<ul class='wsite-menu'>
<li id='wsite-nav-226730044254468285'><a href='/blog.html'><span class='wsite-menu-title'>Blog</span></a>
</li>
</ul>
</div>
</li>
<li id='pg336904325932674008'><a href='/practice-areas.html'>Practice Areas</a>
</li>
<li id='pg342722679661255807'><a href='/press.html'>Press</a>
</li>
<li id='pg204649403653981064'><a href='/contact.html'>Contact</a>
</li>
</ul>
</div>
You should use border-top instead of overline, with some padding-top to pad up the spacing between the string and the top overline.
Just note that am using border-top: 4px solid transparent; which is just a transparent border to reserve the space, because if you won't use that, your menu items will shake on :hover as CSS Default Box Model counts the border outside the element instead of inside, which will result in element nudging..
Demo
HTML
<ul>
<li>Hello</li>
<li>World</li>
</ul>
CSS
ul {
margin: 40px;
}
ul li {
display: inline-block;
padding-top: 5px;
margin-right: 10px;
border-top: 4px solid transparent;
}
ul li:hover {
border-top: 4px solid #f00;
}
Controlling the width using :before or :after pseudo, HTML stays as above..
Demo 2
CSS
ul {
margin: 40px;
}
ul li {
display: inline-block;
padding-top: 8px;
margin-right: 10px;
position: relative;
}
ul li:after {
position: absolute;
width: 90%;
content: "";
top: 0;
left: 50%;
margin-left: -45%;
}
ul li:hover:after {
border-top: 4px solid #f00;
}
they use border-top instead of overline. Please change this
#nav-wrap .container ul li a:hover {
/*background:url(nav-bg-hover-medium.jpg) repeat-x top ;*/
color: #145D85;
text-decoration:overline;
}
into this
#nav-wrap .container ul li a {
border-top:2px solid transparent;
}
#nav-wrap .container ul li a:hover {
color: #145D85;
border-top:2px solid #145D85;
}
<ul>
<li> Item 1 </li>
<li> Item 2 </li>
<li> Item 3
<ul>
<li> Sub Item 1 </li>
<li> sub Item 1 </li>
</ul>
</li>
</ul>
CSS
body
{
background:grey;
}
ul li ul
{
display:none;
}
ul
{
list-style-type:none;
}
ul li
{
float:left;
width:130px;
margin:0px;
padding:10px;
background-color:#003366;
text-align:center;
}
ul li a{
color:white;
text-decoration:none;
}
ul li:hover
{
border-top:4px solid white;
margin-top:-4px;
}
ul li:hover ul
{
display:block;
margin-left:-50px;
margin-top:10px;
}
ul li ul li
{
background-color:#ffffff;
height:100%;
padding:10px;
}
ul li ul li a
{
color:#003366;
}
fiddle
Output:
You could place your menu in a <span></span> and set border-top for that span.
Related
I want to make navigation menu like the picture above with hover on Menu. This is my sample code for the navigation menu.
<div id="menu">
<ul>
<li>Menu1
<ul class="submenu">
<li>Menu1Sub1</li>
<li>Menu1Sub2</li>
<li>Menu1Sub3</li>
<li>Menu1Sub4</li>
</ul>
</li>
<li>Menu2
<ul class="submenu">
<li>Menu2Sub1</li>
<li>Menu2Sub2</li>
<li>Menu2Sub3</li>
</ul>
</li>
...
</ul>
</div>
Submenu position are in a line and I also want Submenu position to be exactly same for each Menu if possible.
How to do this with css?
this is what I tried so far not working as I intended.
#menu {
text-decoration:none;
}
#menu li {
line-height:20px;
float:left;
}
#menu li > ul {
display: none;
}
#menu li:hover > ul {
display: block;
}
#menu li ul li {
line-height:13px;
float:left;
position:relative;
}
Any help would be very appreciated.
try this code:
#menu {
position: relative;
background-color: black;
text-decoration:none;
}
#menu li {
background-color: green;
padding: 10px;
height: 30px;
list-style: none;
line-height:30px;
float:left;
}
#menu li > ul {
display: none;
}
#menu > ul > li {
border: 2px solid white;
}
#menu > ul > li:hover {
border: 2px solid black;
}
#menu li:hover > ul {
display: block;
position: absolute;
top: 54px;
left: 0;
}
#menu li ul li {
float:left;
position:relative;
}
DEMO jsfiddle
Trying to get the words in my navigation bar to center. I have tried a bunch of different configs that I found online and so far no luck.
Also, is there anything I can do to make the navigation bar appear cleaner and more professional?
Thank you in advance
<div class="nav-container clearfix">
<ul id="nav">
<li class="first"><span>Home</li>
<li><span>Why Soy?</li>
<li><span>Candle Sold, Tree Planted</li>
<li><span>Build-a-Candle</li>
<li><span>Contact Us</li>
<li><a class="category" href="<?php echo Mage::getBaseUrl(); ?>all-products">
<span>Buy Products</span>
<ul class="level0">
<?php echo $_menu ?>
</ul>
</a>
</li>
</ul>
/*** CLEARFIX ******/
.clearfix:before,
.clearfix:after {
content: "";
display: table;
clear: both
}
/********** < Navigation */
.nav-container {clear: both; width:100%; float: left; text-align: center; margin: 10px 0px 10px; text-transform: uppercase; font-weight: bold; display: inline; background:#d4dadd !important; box-shadow: 10px 10px 5px #888888 !important; }
#nav { margin:0 auto; padding:0; font-size:12px; }
/* All Levels */ /* Style consistent throughout all nav levels */
#nav li {
display: inline-block;
padding: 5px;
margin: 5px;
border-right: 1px solid #000;
list-style: none;
vertical-align: top;
height: 50px;
position:relative;
}
#nav li.over { z-index:998; background-color: #b3bec3; }
#nav a,
#nav a:hover { display:block; line-height:1.3em; text-decoration:none; padding: 10px;
text-align: center; }
#nav span { display:block; cursor:pointer; }
#nav li ul span {white-space:normal; }
#nav ul li.parent a {}
#nav ul li.parent li a { background-image:none; }
#nav a.category span { background: url(../images/nav-category.gif) no-repeat center right; padding-right: 20px; }
/* 0 Level */
#nav li.active a { color:#2882ce; }
#nav a { font-size: 115%; color:#303030; }
#nav li.last a { padding-right: 0px !important;}
#nav li.over a,
#nav a:hover { color:#2882ce; }
/* 1st Level */
#nav ul li,
#nav ul li.active { float:none; margin:0; padding-bottom:1px; background:#d4dadd; }
#nav ul li.last { background:#d4dadd; padding-bottom:0; }
#nav ul a,
#nav ul a:hover { float:none; padding:0; background:none; }
#nav ul li a { font-size: 100% !important; font-weight:normal !important; }
/* 2nd Level */
#nav ul,
#nav div { position:absolute; width:15em; top:27px; left:-10000px; border:1px solid #899ba5; }
#nav div ul { position:static; width:auto; border:none; }
/* 3rd+ Level */
#nav ul ul,
#nav ul div { top:5px; }
#nav ul li a { background:#d4dadd; }
#nav ul li a:hover { background:#b3bec3; }
#nav ul li a,
#nav ul li a:hover { color:#2f2f2f !important; }
#nav ul span,
#nav ul li.last li span { padding:3px 15px 4px 15px; }
/* Show menu */
#nav li ul.shown-sub,
#nav li div.shown-sub { left:0; z-index:999; }
#nav li .shown-sub ul.shown-sub,
#nav li .shown-sub li div.shown-sub { left:100px; }
<div class="nav-container clearfix">
<ul id="nav">
<li class="first"><span>Home</li>
<li><span>Why Soy?</li>
<li><span>Candle Sold, Tree Planted</li>
<li><span>Build-a-Candle</li>
<li><span>Contact Us</li>
<li><a class="category" href="<?php echo Mage::getBaseUrl(); ?>all-products">
<span>Buy Products</span>
<ul class="level0">
<?php echo $_menu ?>
</ul>
</a>
</li>
</ul>
I changed your code a bit, here is a snippet below, to see this snippet working click Full Page button.
UPDATED snippet based on OP's Comments to answer.
/*** CLEARFIX ******/
.clearfix:before,
.clearfix:after {
content: "";
display: table;
clear: both
}
/********** < Navigation */
.nav-container {
clear: both;
width: 100%;
float: left;
margin: 10px 0px 10px;
text-transform: uppercase;
font-weight: bold;
display: inline;
background: #ecf3f6 !important;
box-shadow: 10px 10px 5px #888888 !important;
}
#nav {
margin: 0 auto;
padding: 0;
font-size: 12px;
}
/* All Levels */
/* Style consistent throughout all nav levels */
#nav li {
display: inline-block;
margin: 5px 0;
border-right: 1px solid #000;
list-style: none;
vertical-align: top;
height: 70px;
width:16.3%
}
#nav li:last-child {
border-right: 0
}
#nav li.over {
z-index: 998;
background-color: #d4dadd;
}
#nav a,
#nav a:hover {
display: block;
line-height: 1.3em;
text-decoration: none;
padding: 10px;
text-align: center
}
#nav span {
display: block;
cursor: pointer
}
#nav li ul span {
white-space: normal;
}
#nav ul li.parent a {} #nav ul li.parent li a {
background-image: none;
}
#nav a.category span {
background: url(../images/nav-category.gif) no-repeat center right;
padding-right: 20px;
}
/* 0 Level */
#nav li.active a {
color: #2882ce;
}
#nav a {
font-size: 115%;
color: #303030;
}
#nav li.last a {
padding-right: 0px !important;
}
#nav li.over a,
#nav a:hover {
color: #2882ce;
}
/* 1st Level */
#nav ul li,
#nav ul li.active {
float: none;
margin: 0;
padding-bottom: 1px;
background: #ecf3f6;
}
#nav ul li.last {
background: #ecf3f6;
padding-bottom: 0;
}
#nav ul a,
#nav ul a:hover {
float: none;
padding: 0;
background: none;
}
#nav ul li a {
font-size: 100% !important;
font-weight: normal !important;
}
/* 2nd Level */
#nav ul,
#nav div {
position: absolute;
width: 15em;
top: 27px;
left: -10000px;
border: 1px solid #899ba5;
}
#nav div ul {
position: static;
width: auto;
border: none;
}
/* 3rd+ Level */
#nav ul ul,
#nav ul div {
top: 5px;
}
#nav ul li a {
background: #ecf3f6;
}
#nav ul li a:hover {
background: #d5e4eb;
}
#nav ul li a,
#nav ul li a:hover {
color: #2f2f2f !important;
}
#nav ul span,
#nav ul li.last li span {
padding: 3px 15px 4px 15px;
}
/* Show menu */
#nav li ul.shown-sub,
#nav li div.shown-sub {
left: 0;
z-index: 999;
}
#nav li .shown-sub ul.shown-sub,
#nav li .shown-sub li div.shown-sub {
left: 100px;
}
<div class="nav-container clearfix">
<ul id="nav">
<li class="first"><span>Home</span>
</li>
<li>whysoy<span>Why Soy?</span>
</li>
<li>plantatree<span>Candle Sold, Tree Planted</span>
</li>
<li><span>Build-a-Candle</span>
</li>
<li><span>Contact Us</span>
</li>
<li><a class="category" href=""><span>Buy Products</span>
<ul class="level0">
</ul>
</a>
</li>
</ul>
</div>
UPDATE #3 (with new info from OP)
in order to achieve what you want, just make this changes below on your CSS:
.nav-container {
background: none repeat scroll 0 0 #d4dadd !important;
box-shadow: 10px 10px 5px #888888 !important;
float: left;
font-size: 0;
font-weight: bold;
margin: 10px 0;
text-align: center;
text-transform: uppercase;
width: 100%;
}
#nav li {
border-right: 1px solid #000;
display: inline-block;
font-size: 12px;
height: 50px;
list-style: none outside none;
margin: 5px 0;
padding: 5px;
position: relative;
vertical-align: top;
width: 15%;
}
#nav ul li, #nav ul li.active {
background: none repeat scroll 0 0 #d4dadd;
border-right: 0 none;
display: block;
float: none;
margin: 0;
width: 100%;
}
/*you may delete this:
#nav ul li.last {
}*/
good day i need help to separate my navigation bar the WELCOME ADMIN should be on the right side here is my code.
HTML
<div id="menu">
<ul>
<li>item1</li>
<li>item1<ul>
<li>item1</li>
<li>item1</li>
<li>item1</li></ul>
</li>
<li>item1</li>
<li>item1<ul>
<li>item1</li>
<li>item1</li>
<li>item1</li></ul>
</li>
<li class="right"><a href="#" >Welcome Admin</a>
<ul>
<li>Subitem One</li>
li>Subitem Two</li>
<li>Subitem Three</li>
</ul>
</li>
</ul>
</nav>
CSS
#menu {
background:#000;
width:100%;
margin-top:0px;
height:40px;
border-radius: 3px;
}
#menu ul ul {
display: none;
}
#menu ul li:hover > ul {
display: block;
}
#menu ul {
background: #000
padding: 0px;
border-radius: 5px;
float:left;
list-style: none;
margin-top:-20px;
position: relative;
display: inline-table;
}
}
#menu ul:after {
content: ""; clear: both; display: block;
}
#menu ul li {
float: left;
}
#menu ul li:hover {
color:#fff;
}
#menu ul li:hover a {
background:#fff;
color: #000;
}
#menu ul li a {
display: block; margin-top:20px;
padding:10px 5px;
color: #FFF; text-decoration: none;
}
#menu ul ul {
background: #fff;
padding:0;
position: absolute;
top: 80px;
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
}
#menu ul ul li {
float: none;
position: relative;
}
#menu ul ul li a {
padding: 15px 40px;
color: #fff;
}
#menu ul ul li a:hover {
background: #000;
color:#fff;
}
thankyou for your answers badly need your help for this projects thankyou for those who will answer
You need to specify the width of the ul as 100% otherwise the float:left on it collapses the uls width.
The just float the last li to the right.
JSFiddle Demo
CSS
#menu {
background:#000;
width:100%;
margin-top:0px;
height:40px;
border-radius: 3px;
}
#menu ul ul {
display: none;
}
#menu ul li:hover > ul {
display: block;
}
#menu ul {
background: #000;
width:100%;
padding: 0px;
border-radius: 5px;
float:left;
list-style: none;
margin-top:-20px;
position: relative;
display: inline-table;
}
#menu ul:after {
content: ""; clear: both; display: block;
}
#menu ul li {
float: left;
}
#menu ul li:hover {
color:#fff;
}
#menu ul li:hover a {
background:#fff;
color: #000;
}
#menu ul li a {
display: block; margin-top:20px;
padding:10px 5px;
color: #FFF; text-decoration: none;
}
#menu ul ul {
background: #fff;
padding:0;
position: absolute;
top: 80px;
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
}
#menu ul ul li {
float: none;
position: relative;
}
#menu ul ul li a {
padding: 15px 40px;
color: #fff;
}
#menu ul ul li a:hover {
background: #000;
color:#fff;
}
#menu ul li.right {
float:right;
}
I have corrected your css and updated here.
html
<div id="menu">
<ul>
<li>item1 </li>
<li>item1
<ul>
<li>item1 </li>
<li>item1 </li>
<li>item1 </li>
</ul>
</li>
<li>item1 </li>
<li>item1
<ul>
<li>item1 </li>
<li>item1 </li>
<li>item1 </li>
</ul>
</li>
<li class="last">
Welcome Admin
<ul>
<li>Subitem One</li>
<li>Subitem Two</li>
<li>Subitem Three </li>
</ul>
</li>
</ul>
</div>
css
#menu {
background:#000;
width:100%;
height:40px;
border-radius: 3px;
float:left;
}
#menu ul ul {
display: none;
}
#menu ul li:hover > ul {
display: block;
}
#menu ul {
padding: 0px;
border-radius: 5px;
list-style: none;
margin:0;
position: relative;
display: block;
}
#menu ul:after {
content:"";
clear: both;
display: block;
}
#menu ul li {
float: left;
}
#menu ul li:hover {
color:#fff;
}
#menu ul li:hover a {
background:#fff;
color: #000;
}
#menu ul li a {
display: block;
padding:0 10px;
color: #FFF;
text-decoration: none;
line-height:40px;
}
#menu ul ul {
background: #fff;
padding:0;
position: absolute;
top: 40px;
box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
}
#menu ul ul li {
float: none;
position: relative;
}
#menu ul ul li a {
padding: 15px 40px;
color: #fff;
}
#menu ul ul li a:hover {
background: #000;
color:#fff;
}
#menu ul li.last {
float:right;
}
I'm stuck with a drop down menu. The problem is that the "parent" link is jumping.
HTML:
<ul id="nav">
<li><span>Page 1</span>
<ul>
<li><a>Extralong Page 1.1</a></li>
<li><a>Page 1.2</a></li>
<li><a>Page 1.3</a></li>
</ul>
</li>
<li>Page 2</li>
<li><span>Page 3</span>
<ul>
<li><a>Page 3.1</a></li>
<li><a>Long description for page 3.2</a></li>
<li><a>Page 3.3</a></li>
<li><a>Page 3.4</a></li>
</ul>
</li>
</ul>
CSS:
* {
margin: 0;
padding: 0;
}
#nav {
float: right;
}
#nav ul {
float: left;
}
#nav li {
float: left;
padding-top: 2px;
list-style: none;
background: #3451ff;
}
#nav li a,
#nav li span {
display: block;
text-decoration: none;
font-size: 12pt;
font-weight: bold;
padding: 13px 10px 9px 10px;
}
#nav li a:link, #nav li a:active, #nav li a:visited,
#nav li span {
color: #FFF;
}
#nav li a:hover, #nav li a.active,
#nav li span:hover {
color: #000;
}
#nav li li {
display: none;
}
#nav li:hover li {
display: block;
float: none;
background: #555;
}
#nav li li a {
font-size: 10pt;
margin: 1px;
width: 100%;
background: #3c6f3a;
padding: 5px 0;
}
Demo
How can I make this parent static such that it's width isn't changed on hover? I don't want to use js.
Set a width for the parent:
#nav li {
float: left;
padding-top: 2px;
list-style: none;
width: 100px; /* Add this bad boy */
background: #3451ff;
}
DEMO HERE
You can use position:absolute and make its parent li position:relative Demo
#nav ul {
position:absolute;
right:0;
}
Use position:relative for ul parent and give position:absolute for parent child..it will be working fine.
Here is the updated fiddle :http://jsfiddle.net/nikhilvkd/gmU55/5/
#nav li li {
display: none;
position:relative;
}
#nav li:hover li {
display: block;
float: none;
position:absolute;
background: #555;
}
i've a menu with sub menus in it, i've added border at bottom while hovering but when i hover on the menu the menu height increases a bit, the whole menu takes a space at top and bottom when i put it in a div.
here is my fiddle : http://jsfiddle.net/p7Nsf/
<div class="head"></div>
<div class="menudiv">
<div class="menu">
<ul>
<li>Home</li>
<li>About
<ul>
<li>School</li>
<li>Vision and Mission </li>
<li>Principal’s desk
<li>Management
</ul> </li>
<li>Admission
<ul>
<li>Overview</li>
<li>Download application form</li>
</ul> </li>
<li>Gallery</li>
<li>School Calander</li>
<li>News & Events</li>
<li>Career</li>
<li>Contact</li>
</ul>
</div>
</div><!-- menu div ends-->
<div class="foot"></div>
CSS
.menudiv
{
width:980px;
}
.menu {
font-family: 'Open Sans', sans-serif;
font-size:14px;
}
.menu ul ul {
display: none;
}
.menu ul li:hover > ul {
display: block;
}
.menu ul {
background: #111312;
list-style: none;
position: relative;
display: inline-table;
border:3px solid #111312;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
.menu ul:after {
content: "";
clear: both;
display: block;
}
.menu ul li {
float: left;
}
.menu ul li:hover {
background: #111312;
border-bottom: 3px solid #fff;
}
.menu ul li:hover a {
color: #fff;
}
.menu ul li a {
display: block;
padding-top: 10px; padding-left: 25px; padding-right: 25px; padding-bottom: 10px;
color: #fff;
text-decoration: none;
}
.menu ul ul {
background: #111312;
padding: 0;
position: absolute;
top: 100%;
}
.menu ul ul li {
float: none;
position: relative;
}
.menu ul ul li a {
padding: 10px;
color:#000;
display: block;
}
.menu ul ul li a:hover {
background: #111312;
color: #fff;
}
.menu ul ul ul {
position: absolute;
left: 100%;
top:0;
padding: 0;
}
.menu ul ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid pink;
position: relative;
}
.menu ul ul ul li a {
padding: 10px;
color: #fff;
display: block;
}
.menu ul ul ul li a:hover {
background: #95CEF1;
color: #000;
}
.menu ul ul ul ul {
position: absolute;
left: 100%;
top:0;
}
.head
{
width:500px;
height:200px;
background:#789;
}
.foot
{
width:500px;
height:200px;
background:#123;
}
Try this, your menu item jumps because you are adding border to the item so it increases its height by the 3 px border
.menu ul li {
float: left;
border-bottom: 3px solid transparent;
}
http://jsfiddle.net/p7Nsf/1/
reduce padding on the anchor to compensate for the 3px
.menu ul li a {
padding-bottom: 7px;
}
http://jsfiddle.net/p7Nsf/2/
Update
.menu ul {
background: none repeat scroll 0 0 #111312;
border: 3px solid #111312;
display: inline-table;
list-style: none outside none;
margin: 0;
padding: 0;
position: relative;
}
I removed the display prop
http://jsfiddle.net/p7Nsf/4/