so I have this navbar in my project, and as it stands at the moment, the text changes color as you hover over it.
jsfiddle of this here
HTML:
<div class = "container">
<div class = "header">
<div class = "header-main">
</div>
<div class = "header-nav">
<ul>
<li><a class = "active" href="#">Home</a></li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
CSS:
* {
padding = 0;
margin = 0;
}
.container {
margin: 0 auto;
width: 940px;
}
.header-main{
border-bottom: 1px solid #dadada;
padding: 20px 0;
}
.header-nav {
padding: 0 0;
}
.header-nav ul {
list-style: none;
}
.header-nav ul li {
float: left;
margin-right: 20px;
}
.header-nav ul li a {
color: #737373;
text-decoration: none;
font-size: 18px;
font-family: 'Novecentosanswide-DemiBold';
text-transform: uppercase;
}
.header-nav ul li a.active {
color: #2ecc71;
}
.header-nav ul li a:hover {
color: #3e3e3e;
}
What I'd like to know is how I can add a box that changes color behind (EDIT: and spans the height of the nav) when you hover over it. The best example I can find of this is Windows 10's site
1. Set links to block elements
2. Add padding to the links (not the list items)
.header-nav ul li a {
color: #737373;
text-decoration: none;
font-size: 18px;
font-family: 'Novecentosanswide-DemiBold';
text-transform: uppercase;
display: block;
padding: 4px 8px;
}
3. Set background-color to the links
.header-nav ul li a.active {
background-color: #2ecc71;
}
.header-nav ul li a:hover {
background-color: #3e3e3e;
}
4. Clear ul
.header-nav ul:after {
clear: both;
content: "";
display: table;
}
5. ???
6. PROFIT
https://jsfiddle.net/BramVanroy/82n0rwb7/9/
Maybe it looks prettier without the margin on the list items? Like so.
(I just noticed that there was an error in your fiddle's CSS. You set margin = 0 to *, but the designator should be a colon not an equal sign, like so: margin: 0.)
.header-nav ul li a {
display:block;
padding:10px;
color: #737373;
text-decoration: none;
font-size: 18px;
font-family: 'Novecentosanswide-DemiBold';
text-transform: uppercase;
}
.header-nav ul li a:hover {
color: #fff;
background:#000;
padding:10px;
}
Eidting these two style classes will do the trick i think. Check it out.
You have to take control of the element size. You can do the trick with
// apply hover to li instead a
.header-nav ul li:hover {
color: #3e3e3e;
background-color: red;
}
// remove the margins for the ul
.header-nav ul {
margin-top: 0px;
margin-bottom: 0px;
}
// implement the margins of the ul on li but as padding instead of margin
.header-nav ul li {
padding-top: 10px;
padding-bottom: 10px;
}
see fiddle example
Few things which you missed:
Clearing the float
Removing margin,bottom from ul which cause unexpected dimensions.
Adding a padding to the link anchors.
CSS::
* {
padding=0;
margin=0;
}
.container {
margin: 0 auto;
width: 940px;
}
.header-main {
border-bottom: 1px solid #dadada;
padding: 20px 0;
}
.header-nav {
padding: 0 0;
}
.header-nav ul {
list-style: none;
margin:0;
padding:0;
}
.header-nav ul li {
float: left;
margin-right: 20px;
}
.header-nav ul li a {
color: #737373;
text-decoration: none;
font-size: 18px;
font-family:'Novecentosanswide-DemiBold';
text-transform: uppercase;
padding:5px 10px;
}
.header-nav ul li a.active {
color: #2ecc71;
background-color:#BFBFBF;
}
.header-nav ul li a:hover {
color: #3e3e3e;
background-color:#BFBFBF;
}
.header-nav ul:after {
clear:both;
content:"";
display:block;
}
Demo: https://jsfiddle.net/lotusgodkk/82n0rwb7/5/
Related
I would like my hover effect to be complete, like in the picture. Mine highlights only a tiny bit around the text.
What am I missing? Please add an explanation to the solution.
http://jsfiddle.net/terzista/9vtpyojh/
css:
.nav
{
margin:0 auto;
width:100%;
position: absolute;
top:0px;
left:0px;
z-index: 4;
background-color:rgba(172,175,176,0.68);
}
.nav ul
{
text-align: center;
}
.nav li
{
width: 6em;
letter-spacing:0.1em;
display: inline-block;
text-decoration: none;
text-transform: uppercase;
}
.nav a{
/*display: inline-block;*/
text-decoration: none;
color: #D12C2C;
}
.nav li:hover
{
color: #666;
background-color: #ED8C8C;
}
.nav li:hover a
{
color: #fff;
}
Modify the following selectors in your css,
.nav ul
{
text-align: center;
margin:0;
}
.nav li
{
width: 6em;
letter-spacing:0.1em;
display: inline-block;
text-decoration: none;
text-transform: uppercase;
padding:10px;
}
The only thing being highlighted is your li. If your ul has margin, then there will be space between the highlighted li and the rest of your ul (so to speak). Removing the margin from ul, then adding padding:10px to get that same "buffer zone" allows it to look the same, but also give the highlight you want.
.nav
{
margin:0 auto;
width:100%;
position: absolute;
top:0px;
left:0px;
z-index: 4;
background-color:rgba(172,175,176,0.68);
}
.nav ul
{
text-align: center;
margin:0;
}
.nav li
{
width: 6em;
letter-spacing:0.1em;
display: inline-block;
text-decoration: none;
text-transform: uppercase;
padding:10px;
}
.nav a{
/*display: inline-block;*/
text-decoration: none;
color: #D12C2C;
}
.nav li:hover
{
color: #666;
background-color: #ED8C8C;
}
.nav li:hover a
{
color: #fff;
}
<section class="nav">
<nav>
<ul>
<li>Home</li>
<li>about</li>
<li>contact</li>
</ul>
</nav>
</section>
I'm trying to keep the parent nav background active when on child page.
Example: Portfolio---->Programs
When my current page is Programs, I'd like to keep the Portfolio active on the navigation bar.
The code use in the CSS is:
/* Navigation
--------------------------------------------------------------------------------*/
#nav-wrap {
max-height: 200px;
}
#nav .container ul {
list-style: none !important;
}
#nav .container ul li {
list-style: none !important;
}
#nav .container ul span:last-child li,
#nav .container ul > li:last-child {
/*background: none;*/
background:url(surf_40.gif) no-repeat -12px;
}
#nav ul li a {
display: block;
font-size:30px;
line-height: 35px;
padding: 10px 0;
color: rgba(255,255,255,0.4);
padding: 2px 25px 2px 21px;
border: 0;
outline: 0;
list-style-type: none;
position:relative;
right:-4px;
z-index:1;
text-transform: uppercase;
font-family: 'Aller', sans-serif;
}
#nav ul li#active a {
background: url(surf_40.gif) no-repeat -12px;
}
#nav ul li#active a,
#nav ul li a:hover {
color: #fff;
border: 0;
}
/**Text modified added - for active parent while my current page is a sub-menu***/
#wsite-menus .wsite-menu li #active a #nav ul li a {
color: #fff;
border: 0;
}
/*---*/
/* Navigation Submenu's
--------------------------------------------------------------------------------*/
#wsite-menus .wsite-menu li a {
color: rgba(0,0,0,0.4);
font-weight: bold;
background: #fff;
/*border: 0 px;*/
border: solid thick;
border-radius: 1em;
/* fine modifica*/
position:relative;
right: 0 px;
}
#wsite-menus .wsite-menu li a:hover {
color: #000;
background: #e3e3e3;
border: solid thick orange;
}
thank you for any help..
HTML code:
<div id="nav">
<ul class='wsite-menu-default'>
<li id='pg962547086691527768'><a href="/" data-membership-required="0" >Home</a></li>
<li id='pg623326219140352077'><a href="/about.html" data-membership-required="0">About</a</li>
</ul></div>
Put the :hover on li's instead of a:hover and alos add class active to li. if you provide html two then i will provide you the perfect solution thanks
I am trying to make a simple vertically aligned menu that has a width of 100%. However, there is some weird padding on the left that prevents the menu from stretching the whole 100%.
HTML
<div class="sidecontent">
<nav class="sidemenu">
<ul>
<li>T-Shirts</li>
<li>Long Sleeve T's</li>
<li>Hoodies</li>
<li>Towels</li>
<li>Design Your Own</li>
</ul>
</nav>
</div>
CSS
div.sidecontent {
width: 100%;
background-color: #E6E6E6;
border-radius: 0 0 10px 10px;
}
nav.sidemenu {
width: 100%;
}
nav.sidemenu ul {
list-style-type: none;
margin: 0;
}
nav.sidemenu ul li {
width: 100%;
border-top: 1px solid #999999;
}
nav.sidemenu ul li:first-child {
border-top: 0;
}
nav.sidemenu ul li:last-child a {
border-radius: 0 0 10px 10px;
}
nav.sidemenu ul li a:link, nav.sidemenu ul li a:visited {
display: block;
font-weight: bold;
font-size: 1em;
text-align: center;
font-family: "Trebuchet MS";
text-decoration: none;
text-transform: uppercase;
color: #4C4C4C;
padding: 28px 0;
}
nav.sidemenu ul li a:hover, nav.sidemenu ul li a:active {
background-color: #CCCCCC;
}
Here is the jsfiddle
Solution
nav.sidemenu ul {
list-style-type: none;
margin: 0;
padding:0;
}
It's the unordered list indent, try adding this to your css:
ul {
list-style:none;
padding-left:0;
}
According to Chrome's HTML inspector, the ul object appears to have sever hidden characteristics:
ul, menu, dir {
display: block;
list-style-type: disc;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px; //this is what's bothering you
}
Hence you want to set the padding-left to 0 px for ul objects:
nav.sidemenu ul {
list-style-type: none;
margin: 0;
padding-left: 0; //this is what I added
}
Fixed fiddle: http://jsfiddle.net/awcPd/5/
I am having a simple problem with my CSS dropdown menu, I want to make it so the dropdowns are equal length to the button above them. See example below, I just want to stretch the block to the length of the above block.
New user, can't upload image
If you use my jsFiddle link you can see my code, and edit it live. I'll post the code anyway just in case.. Note I am only posting the CSS stylesheet in here as the HTML is not part of the problem.
/* Dropdown Menu */
#nav {
float: right;
width: 600px;
height: 90px;
margin: 0 auto;
padding-top: 65px;
}
#nav ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
float: right;
}
#nav ul li {
display: block;
position: relative;
float: left;
}
#nav li ul { display: none; }
#nav ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #3636FE;
margin-left: 1px;
white-space: nowrap;
}
#nav ul li a:hover { background: #3636FE; }
#nav li:hover ul {
display: block;
position: absolute;
}
#nav li:hover li {
float: none;
font-size: 11px;
}
#nav li:hover a { background: #3636FE; }
#nav li:hover li a:hover { background: #6868FE; }
Fixed. (at least for Chrome+Firefox+IE9)
http://jsfiddle.net/QZWj3/4/
You had to add width: 100% to #nav li:hover ul and to #nav li:hover li
I have a nav bar with a drop down that is working beautifully. The only thing I am trying to change, is when you hover over the main links, the sub-links/text are on top of eachother. I want them to display horizontally. I have tried all sorts of floats and display inline etc...
Here is a portion of the HTML:
<ul id="top_main_nav" style="float:left;">
<li>Me
<ul>
<li><?php echo ($auth->first_name); ?> <?php if(strlen($auth->last_name) > 6) { echo substr(strtoupper($auth->last_name),0,6) . "..."; }else{ echo ($auth->last_name); } ?></li>
<li>Edit My Profile</li>
<li>Settings</li>
<li>Email Settings</li>
</ul>
</li>
</ul>
Here is the css:
#user_nav_future {
margin: 0 auto;
font: bold 12px Arial,Helvetica, sans-serif;
color: #fff;
}
#user_nav_future ul li {
list-style: none;
float: left;
}
#user_nav_future ul li a {
color: #fff;
padding: 10px;
display: block;
text-decoration: none;
}
#user_nav_future li ul {
display: none;
position: absolute;
top: 35px;
right: 160px;
z-index: 1001;
margin: 0;
padding: 0;
}
#user_nav_future li ul a {
color: #666;
display: inline;
float: left;
}
#user_nav_future ul li a:hover {
color: #FF4800;
}
#user_nav_future ul {
padding:0;
margin:0;
list-style:none;
}
#user_nav_future li {
float:left;
position:relative;
text-align:center;
}
#user_nav_future li ul {
display:none;
position:absolute;
top:34px;
left:0;
}
#user_nav_future li ul li {
width:160px;
}
#user_nav_future li:hover ul,#user_nav li.over ul {
display:block;
}
These changes should do the trick:
#user_nav_future {
margin: 0 auto;
font: bold 12px Arial,Helvetica, sans-serif;
color: #fff;
}
#user_nav_future ul {
/* Reset padding / margins on <ul>. Add back in as necessary. */
padding: 0;
margin: 0;
list-style: none;
}
#user_nav_future ul li {
/* Take <li> out of the picture - everything is now being dictated by nested <a> */
padding: 0;
margin: 0;
display: inline;
}
#user_nav_future ul li a {
/* whatever width you want each link to be. Since you've got 10px of left/right padding, true element width will be 180px */
width: 160px;
padding: 10px;
float: left;
position: relative;
text-decoration: none;
text-align: center;
color: #fff;
}
#user_nav_future li ul a {
color: #666;
}
#user_nav_future ul li a:hover {
color: #FF4800;
}
#user_nav_future li ul {
display: none;
position: absolute;
top: 34px;
left: 0;
}
#user_nav_future li:hover ul,#user_nav li.over ul {
display: block;
}
What they're doing is setting all the block elements that are causing your drop downs to go down to inline elements that float so the menu is horizontal.
I've also transferred positioning control over to the <a> elements. That way the entire area of the link will be clickable, rather than just the text.
If the above doesn't work for you, post some of your HTML or a dev link so we can see what's going on.