Reputation: 23
I have these dropdown menus that are functioning properly, except the bottom corners of the menu are not rounded. I included the html, css & jquery code. Would you know why my last list items aren't showing rounded bottom corners?
Thank you for your time!
HTML
<nav>
<ul>
<li><a id="Me" href="#">About Me</a>
<li><a href="#">Favorite Films</a>
<!-- Films Drop-Down Menu -->
<ul>
<li><a id="DC" href="#">DC Cinematic Universe</a></li>
<li><a id="Bond" href="#">James Bond</a></li>
<li><a id="Marvel" href="#">Marvel Cinematic Universe</a></li>
<li><a id="ST" href="#">Star Trek</a></li>
<li><a id="SW" href="#">Star Wars</a></li>
<li><a id="X" href="#">X-Men</a></li>
</ul>
<!-- /Films Drop-Down Menu -->
</li>
<li><a href="#">Favorite TV Shows</a>
<!-- TV Drop Down Menu -->
<ul>
<li><a id="Americans" href="#">Americans, The</a></li>
<li><a id="GoT" href="#">Game of Thrones</a></li>
</ul>
<!-- /TV Drop Down Menu -->
</li>
</ul>
</nav>
CSS
nav {
width: 100%;
height: 2em;
float: left;
position: relative;
background: linear-gradient(hsl(1,79%,30%), hsl(1, 88%, 44%), hsl(2,90%,26%));
border: hsl(1,79%,30%) 2px solid;
border-radius: 20px 20px 0 0;
}
nav ul {
list-style: none;
}
nav li {
width: 33%;
display: inline;
float: left;
position: relative;
}
nav li a {
/* Makes entire block for link clickable - not just text. */
display: block;
color: white;
font-size: 1.5em;
font-weight:bold;
text-shadow: 5px 5px 5px black;
transform:skewX(160deg);
text-decoration: none;
}
nav li a:hover {
color: #FFCC33;
}
nav ul ul {
display: none;
position: absolute;
background: hsla(1,79%,30%,.8);
/*Z-Index enables layering - higher values put elements toward top */
z-index: 99;
}
nav li li {
float: none;
width: 100%;
position: relative;
padding: 10px;
/*border: 1px hsl(1,79%,30%);*/
}
nav li li a {
font-size: 1.25em;
}
/* Round bottom corners of menu items on bottom of drop-down menus. */
nav li li:last-child {
border-radius: 0 0 20px 20px;
}
JQUERY
//DROP-DOWN MENUS
$('nav li').hover(function() {
// stop() stops all animation before slideDown()
$('ul',this).stop().slideDown(250);
},
//When not hovering.
function(){
$('ul',this).stop().slideUp(250);
}
);
//DROP-DOWN MENUS
Upvotes: 1
Views: 450
Reputation: 3245
Everything you have is correct except for the selector for the last li. You need to do one of two things:
nav li ul:last-child {...bottom border radius code...}
Or...
nav li li:last-of-type {...}
This caught me off guard for a while as well and I'm not sure if the implementation changed at some point. :last-child
, as the name indicates, selects the last child of a surrounding element, which is why you need to use it to specify the parent element.
:last-of-type
selects the last of the specified element, li
in this case.
Upvotes: 1
Reputation: 23
The background was applied to the nav ul ul while the border-radius was applied to the nav li li:last-child. Moving the background to nav li li solved the problem.
Upvotes: 0
Reputation: 88
use this css
nav {
width: 100%;
height: 2em;
float: left;
position: relative;
background: linear-gradient(hsl(1,79%,30%), hsl(1, 88%, 44%), hsl(2,90%,26%));
border: hsl(1,79%,30%) 2px solid;
border-radius: 20px 20px 0 0;
}
nav ul {
list-style: none;
}
nav li {
width: 33%;
display: inline;
float: left;
position: relative;
}
nav li a {
/* Makes entire block for link clickable - not just text. */
display: block;
color: white;
font-size: 1.5em;
font-weight:bold;
text-shadow: 5px 5px 5px black;
transform:skewX(160deg);
text-decoration: none;
}
nav li a:hover {
color: #FFCC33;
}
nav ul ul {
display: none;
position: absolute;
background: hsla(1,79%,30%,.8);
/*Z-Index enables layering - higher values put elements toward top */
z-index: 99;
}
nav li li {
float: none;
width: 100%;
position: relative;
padding: 10px;
/*border: 1px hsl(1,79%,30%);*/
}
nav li li a {
font-size: 1.25em;
}
/* Round bottom corners of menu items on bottom of drop-down menus. */
nav li li:last-child {
border-bottom-left-radius:20px;
border-bottom-right-radius:20px;
}
Upvotes: 0
Reputation: 3049
In CSS you can make rounded corners different ways:
The first 10px
is top-left, 2° top-right, 3° bottom-right, 4° bottom-left:
border-radius: 10px 10px 10px 10px;
If you specify only one value, this will round all the corners:
border-radius: 10px;
Or individually:
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
Upvotes: 0
Reputation: 613
Have you tried putting the menu in a div and then declaring specifically last one of the list to be rounded ?
divname li:last-of-type a
{
border-bottom:thin solid black;
border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px;
}
Upvotes: 2