Reputation: 1797
I am having a bit of trouble styling a navigation menu where you can select packages.
This is going to be a nav menu for a mobile website.
The active green li tab I need to be evenly spaced across the full with of the ul
My problem is when I click on the tab to make it active the green doesnt fill up all the li and blue is still visible.
Secondly on the green active tab li I need to display a down arrow at the bottom center of the active tab.
I have included a fiddle with it more or less done, just need help with styling it to finish it off.
<ul id="navlist">
<li><a href='#' class="m-active">Basic</a></li>
<li class="spacer"><a class="m-active"href='#'>Standard</a></li>
<li><a class="m-active"href='#'>Premium</a></li>
</ul>
Upvotes: 0
Views: 646
Reputation: 12869
The blue still displays for a few reasons. I'll go through each of them.
The first reason is that you've given your li
s padding and a blue background color. Yet you assign the green background color to your a
s. Since the a
is contained within the li
, and the li
has padding, the a
couldn't possibly extend the full dimensions of the li
and cover up the blue. View this JSFiddle, where that problem is corrected.
The second reason is that your li
s are set to be inline elements. Inline elements interpret all whitespace in your code (spacebar spaces, new lines, etc.) as a single space between the elements. To get rid of that spacing, get rid of the whitespace between the elements in the code itself. View that here.
Unsolved questions: You'll see that there's still blue visible. This is because borders are rendered outside of the element, and this border doesn't extend the whole height of your li
(let alone the ul
, which also has a blue background set). You'll need to figure out how to handle this. One option is that you could use :before
and :after
pseudoelement so that the spacing between the elements is closed.
The way I usually make arrows is with an :after
pseudoelement. Here are the steps:
position: absolute;
. To make it relative to the parent, we need to explicitly define the position on the parent. So let's go with position: relative;
, as that won't change the location of the parent. Now we can move the arrow around wherever we want!display: block
; and give it empty content. This makes it display as we want it to.Unsolved questions: Right now, your li
s aren't the same width. This means that no single line of CSS code could center the triangles for all of the li
s. You either need to set the li
s to be the same width, then position the triangle, or target each li
individually and manually place the triangle based on the width. I suggest the former of these two possibilities.
And here's how I'd make the menu, with most of the issues above resolved. Maybe this will be a place for you to work from.
If you're not planning on fading the arrow in, then you might prefer to use the border hack to create the triangle, which has deeper browser support.
Upvotes: 1