Skip to content Skip to sidebar Skip to footer

Css :last-child And :hover On An A Link In A Ul

I'm styling the last child of a navigation menu which I seem to be able to do fine with the following code: .aston-menu-light ul > li:last-child { border:2px solid blue;

Solution 1:

you should change

.aston-menu-lightul > li > a:last-child:hover {
    color:red !important;
}

to

.aston-menu-light>ul>li:last-child > a:hover {
    color:red !important;
} 

/* CSS Document */a {
	color: black;
}

nav {
	margin: 50px0;

}

navul {
	padding: 0;
  margin: 0;
	list-style: none;
	position: relative;
	}
	
navulli {
	display:inline-block;
}

nava {
	display:block;
	padding:010px;	
	color:#black;
	font-size:20px;
	line-height: 60px;
	text-decoration:none;
}


/* Hide Dropdowns by Default */navulul {
	display: none;
	position: absolute; 
	top: 60px; /* the height of the main nav */
}
	
/* Display Dropdowns on Hover */navulli:hover > ul {
	display:inherit;
}
	
/* Fisrt Tier Dropdown */navululli {
	width:170px;
	float:none;
	display:list-item;
	position: relative;
}

/* Second, Third and more Tiers	*/navulululli {
	position: relative;
	top:-60px; 
	left:170px;
}

	
/* Change this in order to change the Dropdown symbol */li > a:after { content:  ' +'; }
li > a:only-child:after { content: ''; }

.aston-menu-lightul > li:last-child {
	border:2px solid blue;
	border-radius: 50px;
	padding:020px020px;
} 

.aston-menu-lightul > li > ul > li:last-child {
	border:none !important;
	padding:0!important;
} 

.aston-menu-lightul > li:last-child:hover {
	background-color:#ffff;
	-webkit-transition: all .5s;
	-o-transition: all .5s;
	transition: all .5s;
} 

.aston-menu-light>ul>li:last-child > a:hover {
	color:red !important;
} 
<navclass="aston-menu-light"><ul><li><ahref="#">link</a><!-- First Tier Drop Down --><ul><li><ahref="#">link</a></li><li><ahref="#">link</a></li><li><ahref="#">link</a></li></ul></li><li><ahref="#">link</a><!-- First Tier Drop Down --><ul><li><ahref="#">link</a></li><li><ahref="#">link</a></li><li><ahref="#">link</a></li></ul></li><li><ahref="#">link</a></li><li><ahref="#">link</a><!-- First Tier Drop Down --><ul><li><ahref="#">link</a></li><li><ahref="#">link</a></li><li><ahref="#">link</a></li></ul></li><li><ahref="#">link</a><!-- First Tier Drop Down --><ul><li><ahref="#">link</a></li><li><ahref="#">link</a></li><li><ahref="#">link</a></li></ul></li><li><ahref="#">link</a></li><li><ahref="#">link</a></li></ul></nav>

Solution 2:

Use This:

.aston-menu-lightul > li:last-childa:hover {
  color:red;
}

Solution 3:

You shold rewrite

.aston-menu-lightul > li > a:last-child:hover {
  color:red !important;
} 

to

.aston-menu-lightul > li:last-child > a:hover {
  color:red;
} 

What you were doing wrong is that in all the li elements the a element is always the last child! Therefore in all of them, it will turn red when you hover. What you needed was the last li element, therefore using li:last-childin the CSS.

Also, there is no need to use the !important, since this CSS selector is more specific than just

a {
  color: black;
}

It will be red anyway.

Solution 4:

Just do this to simplify it.

.aston-menu-lightulli:last-childa:hover {
    color:red !important;
}

Post a Comment for "Css :last-child And :hover On An A Link In A Ul"