ul {
list-style-type: none;
padding: 0px 5px 0px 5px;
margin: 0px;
}
ul li {
border-bottom: 1px solid #B9D3EE;
}
ul li a:link,
ul li a:visited,
ul li a:active {
width: 100%;
color: blue;
}
ul li a: hover {
width: 100%;
color: #ffffff;
background-color: #B9D3EE;
}
In IE the above code will highlight the complete cell when hovered.
But in FF it will only highlight the link that is within it.
I would like FF to highlight the complete cell as IE does.
Here is the list:
Keep in mind that only the first link has been created because I have just started creating this list and stopped to test it when I noticed this problem.
<ul>
<li>beauty</li>
<li>creative</li>
<li>Info Tech. (IT)</li>
<li>cycle</li>
<li>event</li>
<li>financial</li>
<li>legal</li>
<li>lessons</li>
<li>medical</li>
<li>marine</li>
<li>pet</li>
<li>automotive</li>
<li>farm+garden</li>
<li>household</li>
<li>labor/move</li>
<li>MKT/COMM</li>
<li>office</li>
<li>skill'd trade</li>
<li>real estate</li>
<li>health/wellness</li>
<li>travel/vac</li>
<li>write/ed/tr8</li>
</ul>
Any help is much appreciated!
You can make your a elements as block elements, so they will get all width of parents elements (demo: http://jsfiddle.net/WasWE/).
ul li a:link, ul li a:visited, ul li a:active {
display: block;
color: blue;
}
ul li a:hover {
background-color: #B9D3EE;
color: #ffffff;
}
Or you can add hover event to li elements (demo: http://jsfiddle.net/XmwTV/):
ul li:hover {
background-color: #B9D3EE;
}
ul li a:link, ul li a:visited, ul li a:active {
color: blue;
}
ul li a:hover {
color: #ffffff;
}
Hi now remove with 100% in your anchor link css and define display block in you css in anchor
as like this
ul li a: link,
ul li a: visited,
ul li a: active {
display:block; // add this line
width:100%; // remove this line
color: blue
}
ul li a:hover{
width:100%; //remove this line
color: #ffffff;
background-color: #B9D3EE;
}
Demo
Related
Whenever I make a link within a list, it inherits the properties of the menu link list in my CSS. I pasted the CSS of the menu list below which keep on passing its properties to any links within any list in my website. I need help as to how can I label the menu list items in a way that they don’t pass their properties to any link in a list.... Please help!
ul li a {display: block;background: #660000;padding: 5px 10px 5px 10px;text-decoration: none;color: #fff; border-left:1px solid #660000;}
ul li a:hover {background: #3300cc; margin: 0; }
li:hover ul {display: block; position: absolute; margin:0; }
li:hover li {float: none; }
li:hover a {background: #3300cc; }
li:hover li a:hover {background: #660000; }
.drop-nav li ul li {border-top: 0px; position: relative; padding:0px; z-index: 100; border-bottom:0px; margin: 0; right:0; left:0; }
li li:hover a {display: block; }
li li ul a {display: none; border-left:1px solid #660000; margin-left: 60px; margin-top:-30px; margin-bottom: 30px; }
li:hover li:hover ul li a:hover {background: #660000; margin-top:-30px; margin-bottom:30px; margin-left: 60px;border-left:1px solid #660000; }
Your help is appreciated!
Use less general selectors in your Menu list like a '.class' instead of 'ul li'.
OR
Use the pseudo :not on your anchor tags used in main area. (Be careful it's not supported by every browser)
beginner girl here who is completely stuck at her first CSS project. Please please tell me what I am doing wrong.
So I have this horizontal menu, with three stupid tabs. I want the background color for the selected tab to be different (done!), and also the font color to be different - which is not happening, despite by best efforts for the past hour.
This is the HTML:
<nav>
<ul>
<li class="selected">Job Description Details</li>
<li>Audit Trail</li>
<li>Files</li>
</ul>
</nav>
And the CSS. Here the background property for the last rule IS APPLIED. But if I add a color one, nothing happens. Does the code have a grudge against me? :(
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
nav {
background-color: #488AC7;
margin: none;
}
nav ul {
margin: 0px;
list-style-type: none;
padding: 5px 0px 5px 0px;
}
nav ul li {
display: inline;
padding: 5px 10px 5px 10px;
}
nav ul li a:link,
a:visited {
color: #F0FFFF;
border-bottom: none;
font-weight: bold;
}
nav ul li.selected {
background-color: #F0FFFF;
border-bottom: none;
}
Try this
nav ul li.selected a, nav ul li.selected a:visited {color:red;}
Add
nav ul li.selected a {
color:red;
}
Color on nav ul li.selected is applied to the text that are no links. You have to specify the color for the links with nav ul li.selected a.
I have some serious problem with my menu and its hover effect.
I have a very basic menu, which has a submenu:
<ul id="menu">
<li>Menu1</li>
<li>Menu2
<ul>
<li>SubMenu1</li>
<li>SubMenu2</li>
</ul>
</li>
<li>Menu3</li>
</ul>
Here is the CSS I'm using:
#menu li {
display: inline;
}
#menu li a {
padding: 10px;
}
#menu li a:hover {
background: #000;
}
#menu ul ul {
display: none;
}
#menu ul li:hover > ul {
display: block;
}
#menu ul ul {
width: 200px;
height: 100px;
background: #000;
}
Okay, so my problem is, that when I hover my mouse the Dropdown menu and gets my mouse on the Submenus, the Hover effect of the Parent menu item (in this case Menu2) is disappearing. So it will not have black BG when I hover the mouse on the submenu items.
Is there anything I could do to make that hover effect stay on the partent menu (Menu2)?
First problem: your selectors are wrong.
#menu IS an ul , then #menu ul ul means
an ul descendant of an ul descendant of my #menu, that is an ul
You don't have three levels of uls, so...
change ul ul to li ul.
The second problem is that you are affecting a tag on hover, but a tag is a sibling, not an ancestor (or parent) of your submenu ul.
You should then target your li, not your a.
Demo: http://jsfiddle.net/mSrkn/ (with tons of problems still there, but with the two above resolved)
#menu li {
display: inline;
}
#menu li a {
padding: 10px;
}
#menu li:hover {
background: #000;
}
#menu li ul {
display: none;
}
#menu li:hover > ul {
display: block;
}
#menu li ul {
width: 200px;
height: 100px;
background: #000;
}
The problem is with yout selectors:
#menu ul li:hover > ul {
display: block;
}
This says that any element with ID that has a child ul with lis that's hovered with a child ul should be selected. Your markup is different from this, the UL itself is the ID #menu so you have to remove the first ul from the selectors themselves:
#menu li:hover > ul {
display: block;
}
http://jsfiddle.net/V7Ltw/
You might try adding the following to your CSS
#menu li:hover{
background-color: #000;
}
By hovering over the sub-menu, you're still hovering over the parent list item.
And you should follow Kyle's answer as well as you do need to remove the first UL selector from your css.
You have to change a lot of stuff to make this work, the basic idea is to put the submenu inside your menu items :
CSS:
#menu li {
display: inline;
}
#menu li a {
padding: 10px;
}
#menu li a:hover {
background: #000;
}
#menu ul.submenu {
display: none;
float: left; // For viewing purpose
}
#menu ul.submenu { padding: 20px; }
#menu ul.submenu:hover {
display: block;
}
#menu li:hover > ul.submenu {
display: block;
}
ul.submenu:hover + a { background: #000; }
#menu ul {
width: 500px;
height: 100px;
background: #000;
}
HTML:
<ul id="menu">
<li>Menu1</li>
<li>
<ul class='submenu'>
<li>SubMenu1</li>
<li>SubMenu2</li>
</ul>
Menu2
</li>
<li>Menu3</li>
</ul>
Demo here : http://jsfiddle.net/V7Ltw/
I'd like to make a black navigation bar for my website, and when you hover over the first link it goes orange, the second link it goes green, etc. I know how to change colour on hover but don't know how to make each link different.
I figure its something to do with giving ids to each li tag?
<div id="navbar">
<ul>
<li id="link1">1</li>
<li id="link2">2</li>
<li id="link3">3</li>
</ul>
</div>
But then how do I create different styles for each of these ids in the css file?
Below is what I tried
#navbar ul li a {
text-decoration: none;
padding-top: 25px;
padding-bottom: 25px;
padding-left: 30px;
padding-right: 30px;
color: #ffffff;
background-color: #000000;
}
#navbar ul li #link1 a:hover {
color: #ffffff;
background-color: #C62222;
padding-top:15px;
padding-bottom:15px;
}
#navbar ul li #link2 a:hover {
color: #ffffff;
background-color: #28C622;
padding-top:15px;
padding-bottom:15px;
}
Help much appreciated!
What you're doing is on the right track, but don't repeat the CSS over and over:
#navbar ul li a:hover {
color: #ffffff;
padding-top:15px;
padding-bottom:15px;
}
#navbar ul #link1 a:hover {
background-color: #C62222;
}
#navbar ul #link2 a:hover {
background-color: #28C622;
}
As others have noted, you also need to either remove the space between the li and your id, or just remove the li entirely (since there is only one link1, you don't necessarily need to tell the browser that it is an li).
Additionally, if you want, you can (and probably should) simply those selectors all the way down to #link1 a:hover and #link2 a:hover. It's more of a stylistic choice, but it helps to keep your code clean.
You have a bad selector. The li is superfluous.
#navbar #link1 a:hover {
color: #ffffff;
background-color: #C62222;
padding-top:15px;
padding-bottom:15px;
}
You need to remove the space between li and #link1:
#navbar ul li#link1 a:hover
You could further optimize your CSS like this:
#navbar a {
text-decoration: none;
padding: 25px 30px; /* shortcode for top/bottom - left/right */
color: #ffffff;
background-color: #000000;
}
#navbar a:hover { /* common hover styles */
color: #ffffff;
padding:15px 30px;
}
#link1 a:hover { /* individual hover styles */
background-color: #C62222;
}
#link2 a:hover { /* individual hover styles */
background-color: #28C622;
}
remove the space between li and #link2.
#navbar ul li#link1 a:hover {
color: #ffffff;
background-color: #C62222;
padding-top:15px;
padding-bottom:15px;
}
#navbar ul li#link2 a:hover {
color: #ffffff;
background-color: #28C622;
padding-top:15px;
padding-bottom:15px;
}
You were close, but the space between li and #linkX is causing problems. These are not two separate elements, so they should be combined. One possible method is:
#navbar ul li#link1 a:hover {
....
Alternately, you can use:
#navbar ul #link1 a:hover {
....
You may wish to combine the duplicated styles into a single directive:
#navbar ul li a:hover {
color: #ffffff;
padding-top:15px;
padding-bottom:15px;
}
Then use only the changed style as needed:
#link1 a:hover {
background-color: #C62222;
}
I'm trying to fashion a 100% CSS and HTML dropdown menu like what's seen on http://phpbb.com. When you hover over the navigation links, a new div appears just below the one you hovered onto.
What I'm trying to do is make .submenu appear just below the <li> that it's nested into by using #nav li a:hover submenu {. To my knowledge this CSS selector should select the .submenu DIV when an a element is hovered over? But it doesn't work.
#nav {
list-style-type: none;
margin: -5px 0px 0px 5px;
}
#nav li {
display: inline;
}
#nav li a {
display: block;
padding: 3px;
float: left;
margin: 0px 10px 0px 10px;
text-decoration: none;
color: #fff;
font-weight: bold;
position: relative;
}
#nav li a:hover {
text-shadow: 1px 1px #333;
}
#nav li a:hover submenu {
display: block;
color: red;
}
.submenu {
position: absolute;
display: none;
}
<ul id="nav">
<li>Home
</li>
<li>
Skins
<div class="submenu">
hello :)
</div>
</li>
<li>Guides
</li>
<li>About
</li>
</ul>
Your second to last selector is looking for a "submenu" element, you should correct this to say ".submenu"
Like this:
/*#nav li a:hover submenu {*/
#nav li a:hover .submenu {
display: block;
color: red;
}
EDIT:
To get the hover to work, you also need to adjust your CSS so that the hover is applied to the list item, instead of the anchor tag:
#nav li:hover .submenu {
display: block;
color: red;
}
Are you missing a period ('.') before submenu in the selector #nav li a:hover submenu?
Try to edit this following part.
Put a . (dot) before the submenu, since its a class.
#nav li a:hover .submenu {
display: block;
color: red;
}
#nav li:hover .submenu {
display: block;
color: red;
}
You want the submenu to appear when you hover on li, not on a, simply because you do not have items with a class submenu inside the a.
Also you could consider using s for the submenus.