css menu bar issue in hover state in html5 - css

This is my css:
.nav {
margin: 0px;
padding: 0px;
list-style: none;
display: table;
width:100%;
text-align: center;
position: relative;
}
.nav li {
display: table-cell;
}
.nav li a {
background: #FF0000;
color: #fff;
display: block;
padding: 7px 8px;
text-decoration: none;
}
.nav li a:hover {
background-color:#000;
border:1px solid #fff;
}
.nav ul {
display: none;
position: absolute;
margin-left: 0px;
list-style: none;
padding: 0px;
display: table;
width: 100%;
left: 0;
visibility: hidden;
}
.nav li:hover ul {
visibility: visible;
}
.nav ul li {
display: table-cell;
}
.nav ul a {
display: block;
height: 15px;
padding: 7px 8px;
color: #fff;
text-decoration: none;
border-bottom: 1px solid #222;
}
.nav ul li a:hover {
color: #069;
}
JSfiddle: http://jsfiddle.net/spog4sqg/3/
Here when hover over HOME display text-decoration:underline;, when hover over other remaining list, display like this: http://s7.postimg.org/br5nkl8zf/Untitled_1_copy.png
May i know, what is the exact css property to fix this.
Thanks in advance..

Basically this is what you're looking for:
.navigation > ul li:first-child a:hover {
background-color: red;
text-decoration: underline;
}
See Example

I used :first-child pseudo-class, hope that helps?
.nav li:first-child a:hover {
text-decoration: underline;
}
http://jsfiddle.net/w81swq5j/2/

I guess, that instead of the underline property, you mean that you want the hover state to stay active when you hover the child list.
In order to do so, trigger the hover effect on the list-item instead of the anchor.
Change:
.nav li a:hover {
background-color:#000;
}
To:
.nav li:hover a {
background-color:#000;
}
Updated Fiddle.
[EDIT]
Hope I understand your comment right. By 'underline' you mean that the submenu gets a background-color?
Then change it to:
.nav li:hover ul li a {
background-color:#000;
}
Updated Fiddle 2.

Related

Styling Another Element Based On CSS :Hover Element

I'm trying to fill a custom bullet point whenever the list item is hovered.
I have the custom bullet:
.navUl li ul li::before {
display: inline-block;
content: "";
border-radius: 50%;
height: 1.5rem;
width: 1.5rem;
margin-right: 0.5rem;
border: 2px solid white;
}
I Have an hover effect to change the text color:
.navUl li ul li:hover {
color: red;
}
But I want to also change styling (fill background) of my custom bullet, so I've tried:
.navUl li ul li:hover > .navUl li ul li::before {
background-color: red;
}
How can I achieve this?
Reference to project in question
Try this
CSS
.navUl li ul li:hover {
color: red;
}
.navUl li ul li:hover:before {
background-color: red;
}
SCSS
.navUl li ul li:hover {
color: red;
&:before{
background-color: red;
}
}

Pure CSS horizontal drop menu, show in click instead of hover [duplicate]

This question already has answers here:
Can I have an onclick effect in CSS?
(14 answers)
Closed 7 years ago.
Is it possible with pure CSS? That instead of showing a dropdown when I hover over "Test", show it when I click on "Test".
Also keep the yellow link color on "Test" when I have that dropdown open.
My current CSS
nav {
text-transform: uppercase;
text-align: center;
margin-bottom: 20px;
}
nav ul {
list-style: none;
}
nav ul li {
display: inline-block;
text-align: left;
}
nav a {
display:block;
padding:0 20px;
transition: color .2s;
color: black;
font-size: 16px;
font-weight: 600;
line-height: 40px;
text-decoration: none;
}
nav ul ul li a { color: #FFFF64; }
nav ul ul li a:hover { color: #99A7EE; }
nav a:hover { color: #FFFF64; }
nav ul ul { display: none; position: absolute; }
nav ul li:hover > ul { display: inherit; }
nav ul ul li { background: #000; display: list-item; position: relative; }
nav ul ul li:hover { background: #333; }
http://jsfiddle.net/hn93jyvc/
You can change :hover to :active like this: http://jsfiddle.net/hn93jyvc/1/
nav ul ul li a { color: #FFFF64; }
nav ul ul li a:active { color: #99A7EE; }
nav a:active { color: #FFFF64; }
nav ul ul { display: none; position: absolute; }
nav ul li:active ul { display: inherit; }
nav ul ul li { background: #000; display: list-item; position: relative; }
nav ul ul li:active { background: #333; }
However, this will not keep state and will only work on mouse down, once you release the mouse button, the menu will disappear.
As far as I know here, you would have to use a bit of javascript to attach active to this element until another click, or the desired logic.
You can see how achieve that from this answer: https://stackoverflow.com/a/20343068/5242026
Albeit, that answer uses jQuery, you could just as well make use of Javascript click event: https://developer.mozilla.org/en/docs/Web/Events/click which makes more sense if there are no other usages for jQuery.
Like i said in my comment. This can be done using the checkbox combined with css pseudo ':checked' selector.
HTML
<ul>
<li>Home</li>
<li><label for="dd">Services</label>
<input type="checkbox" id="dd" hidden>
<ul class="dropdown">
<li>clean</li>
<li>fix</li>
<li>paint</li>
</ul>
</li>
<li>contact</li>
</ul>
CSS
ul{
background: blue;
display:block;
list-style-type: none;
text-align:center;
}
ul li{
display: inline-block;
color: white;
font-family: sans-serif;
font-weight: 800;
font-size: 20px;
padding: 10px 15px;;
position:relative;
// keep users from highlighting text if they click it on/off too fast
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
ul li:hover{
background: #f9a1c6;
color: #000;
}
ul li .dropdown{
display:none;
width: 200px;
padding:0; margin:0;
background: green;
position: absolute;
top: 45px;
left:0;
}
ul li .dropdown li{
width:100%;
display:block;
padding:10px 0px; margin:0px;
}
#dd:checked ~ .dropdown{
display:block;
}
jsfiddle

Shifting un ordered list items to the left ( Wordpress )

Hi I am having trouble shifting a menu list on my wordpress site to the left. It appears as if there is a margin so when the list contains so many items it appears right offset and no longer centred. The site in question is www.cabinboys.ca the menu I'm talking about is right below the cabinboys image filled with two letter items. If any one could look at my css and see if they could figure out how to shift the list items to the left that would be much appreciated thanks.
/* =Menu
----------------------------------------------- */
#menu {
border-bottom: 1px solid #ddd;
border-top: 1px solid #ddd;
margin-bottom: 25px;
padding: 10px;
text-align: right;
width: 800px;
}
#menu img {
margin-bottom: 10px;
}
#menu a {
color: #666;
font-family: 'Oswald', Helvetica, Arial, sans-serif;
font-size: 18px;
margin: 0 10px;
text-decoration: none;
text-transform: uppercase;
}
#menu a:hover {
color: #36bcab;
}
#menu ul {
list-style: none;
margin: 0;
padding-left: 30;
}
#menu li {
float: right;
position: relative;
}
#menu ul ul {
display: none;
float: right;
position: absolute;
right: 0;
z-index: 99999;
}
#menu ul ul ul {
right: 100%;
top: 0;
}
#menu ul ul a {
background: #e9e9e9;
border-bottom: 1px solid #e1e1e1;
display: block;
font-size: 14px;
height: auto;
line-height: 1em;
margin: 0 ;
padding: .8em .5em .8em 1em;
width: 130px;
}
#menu ul ul li:last-of-type a {
border-bottom: none;
}
#menu li:hover > a,
#menu ul ul :hover > a {
color: #36bcab;
}
#menu ul ul a:hover {
background: #36bcab;
}
#menu ul li:hover > ul {
display: block;
}
#menu ul li.current_page_item > a,
#menu ul li.current_page_ancestor > a,
#menu ul li.current-menu-item > a {
color: #111;
}
#menu ul:after {
clear: both;
content: ' ';
display: block;
}
You should add a couple of properties to make it work:
#menu-header-menu {
display:table;
margin:0 auto;
padding:0;
}
Nevertheless it's interesting that you say that the shift happened when the number if items in the menu increased, I don't see in the CSS any code that could differentiate the display depending on the number of items. Could you confirm that I understood the situation?

Navbar dropdown menu fixed width

I'm wondering is there an easy way to fix the width on this dropdown menu?
http://jsfiddle.net/s3bA3/3/
I'd like a box effect dropdown list in the same position as where is says "DROPDOWN"
Seems like it shouldn't bee too hard a fix but I'm pretty new to CSS.
Here's the CSS code:
nav {
width: 100%;
float: left;
margin: 0 0 3em 0;
padding: 0;
list-style: none;
background-color: #242424;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
position:fixed;
top:0px;
}
nav li {
float: left;
}
nav li li {
clear: both;
}
nav li a {
display: block;
padding: 8px 15px;
text-decoration: none;
font-weight: bold;
color: #7ACC01;
border-right: 1px solid #ccc;
}
nav li a:hover {
color: #c00;
background-color: #fff;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
Thanks for reading.
nav ul li:hover > ul {
display: block;
position:absolute;
}
http://jsfiddle.net/AK7Fb/

CSS dropdown menu, clear 1st lvl hover

I'm trying to style menu on my website but I'm stuck with coloring and hover effects.
It looks now as below (/user is where cursor was when I took screenshot):
Screenshot
What I need to change is:
when I hover 2nd level item, 1st level becomes "default" (without hover effect)
My CSS for this menu is:
#nav {
text-align: center;
font-size: 1.5em;
font-weight: 700;
letter-spacing: 1px;
}
#nav ul ul {
display: none;
}
#nav ul li:hover > ul {
display: block;
}
#nav ul {
display: inline-table;
list-style: none outside none;
padding: 0 10px;
position: relative;
}
#nav ul:after {
clear: both;
content: "";
display: block;
}
#nav ul li {
float: left;
background: none repeat scroll 0 0 #F5F5F5;
margin-right: 3px;
}
#nav ul li:hover {
background: none repeat scroll 0 0 #E32D40;
}
#nav ul li a {
color: #757575;
display: block;
padding: 10px;
text-decoration: none;
}
#nav ul li a:hover {
color: #FFFFFF;
}
#nav ul ul {
border-radius: 0 0 0 0;
padding: 0;
position: absolute;
top: 100%;
}
#nav ul ul li {
margin-top: 3px;
float: none;
position: relative;
color: #757575;
}
#nav ul ul li a {
color: #757575;
display: block;
padding: 10px;
text-decoration: none;
}
#nav ul ul li a:hover {
}
#nav ul ul ul {
left: 100%;
position: absolute;
top: 0;
}
I'm not sure, if it is possible with only css. As you are displaying the 2nd level with #nav ul li:hover > ul and you are highlighting the 1st with #nav ul li:hover, which are both firing on 2nd level li hover (and there is no parent call in css).
It is quite easy though with jQuery:
$('#nav > ul > li > ul > li').hover(function () {
$(this).parents('li').first().css('background', 'none');
});
Check here: http://jsfiddle.net/balintbako/EruTP/

Resources