CSS: how to add a down arrow for the active link - css

![enter image description here][1]I have the following CSS navigation that adds an arrow on hover.
How can add an arrow to be visible for the active or on link? i have attached the image as well
Here is my code below
<style type="text/css">
#nav {
margin-top:0;
padding: 12px 0;
margin-left: 0;
background-color: #fafafa;
color: #464646;
-moz-box-shadow: 0 5px 5px #888;
-webkit-box-shadow: 0 5px 5px #888;
box-shadow: 0 5px 5px #888;
}
#nav li {
list-style: none;
display: inline;
margin: 0px;
padding: 0;
padding: 22px;
padding-right: 0;
padding-left: 0;
}
#nav li a {
font-family: Arial;
font-style:normal;
text-transform: uppercase;
text-decoration: none;
color: #464646;
padding: .7em 3em;
border-right: 1px dashed #959595;
}
#nav li a:hover {
background-color: #fafafa;
color: #005596;
font-weight: bold;
}
#nav li:hover {
background: transparent url(images/down_arrow2.png) no-repeat scroll center bottom;
margin: 0;
}
#active a:link, #active a:visited,#active a:hover
{
/* border: 1px solid #333; */
background-color: #fafafa;
color: #005596;
font-weight:bold;
}
</style>
HTML
<ul id="nav">
<li id="active">Home</li>
<li>Photos</li>
<li>Videos</li>
<li>Add a Restaurant</li>
<li>Delete a Restaurant</li>
<li>Logout</li>
</ul>

Use a class name instead if an id:
<li class="active">Home</li>
Then you can do:
#nav li.active {
background: transparent url(images/down_arrow2.png) no-repeat scroll center bottom;
margin: 0;
}

Just add a background image to css.
#active a:link, #active a:visited,#active a:hover
{
/* border: 1px solid #333; */
background-color: #fafafa;
color: #005596;
font-weight:bold;
background: transparent url(images/down_arrow2.png) no-repeat center bottom;
margin: 0;
}

Related

Make top-border cover border completely

I have a nav bar with three links in it. If you look closely, you'll see that the dark green top-border on the hover and active anchors do not cover the brown border. Is there any way to make it do this?
Here's what it looks like;
body {
font-family: 'Roboto', sans-serif;
font-weight: 300;
background-color: #C8E6C9;
margin: 0;
padding: 0;
}
.container {
margin: 0 10% 0 10%;
}
header, ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #4CAF50;
}
h1 {
margin: 0;
border-bottom: 1px solid #FFFFFF;
font-family: 'Roboto', sans-serif;
font-weight: 400;
}
li {
float: left;
margin: 0 0 0 0;
}
h1, li a {
display: block;
color: #FFFFFF;
padding: 14px 16px;
text-decoration: none;
border: 2px solid #4CAF50;
border-top: 6px solid #4CAF50
}
/*link actions*/
li a.active {
background-color: #795548;
border: 2px solid #795548;
border-top: 6px solid #388E3C;
}
li a:hover {
background-color: #FDD835;
border: 2px solid #795548;
border-top: 6px solid #388E3C;
color: #795548;
}
li a.active:hover {
background-color: #FDD835;
border: 2px solid #795548;
border-top: 6px solid #388E3C;
}
a:first-child {
text-decoration: none;
color: #FFFFFF;
}
a:first-child:hover {
color: #795548;
}
<body>
<noscript>Please Use JavaScript you loser.</noscript>
<div class="container">
<header>
<nav>
<h1>My Website</h1>
<ul>
<li>Home</li>
<li>About</li>
<li>Getting Started</li>
</ul>
</nav>
</header>
</div>
</body>
That's the way borders meet. I'd suggest using a box-shadow instead of the top border
NOTE:
You were clearing the floats with overflow:hidden on the ul. This would stop this technique working. I'd suggest an alternative clearfix method.
* {
box-sizing: border-box;
}
body {
font-family: 'Roboto', sans-serif;
font-weight: 300;
background-color: #C8E6C9;
margin: 0;
padding: 0;
}
.container {
margin: 0 10% 0 10%;
}
header,
ul {
list-style-type: none;
margin: 0;
padding: 0;
float: left;
width: 100%;
background-color: #4CAF50;
}
h1 {
margin: 0;
border-bottom: 1px solid #FFFFFF;
font-family: 'Roboto', sans-serif;
font-weight: 400;
}
li {
float: left;
margin: 0 0 0 0;
}
h1,
li a {
display: block;
color: #FFFFFF;
padding: 14px 16px;
text-decoration: none;
border: 2px solid #4CAF50;
border-top: none;
box-shadow: 0 -6px 0px 0px #4CAF50;
}
/*link actions*/
li a.active {
background-color: #795548;
border: 2px solid #795548;
border-top: none;
box-shadow: 0 -6px 0 0px #388E3C;
}
li a:hover {
background-color: #FDD835;
border: 2px solid #795548;
border-top: none;
box-shadow: 0 -6px 0 0px #388E3C;
color: #795548;
}
li a.active:hover {
background-color: #FDD835;
border: 2px solid #795548;
border-top: none;
box-shadow: 0 -6px 0px 0px #388E3C;
}
a:first-child {
text-decoration: none;
color: #FFFFFF;
}
a:first-child:hover {
color: #795548;
}
<div class="container">
<header>
<nav>
<h1>My Website</h1>
<ul>
<li>Home
</li>
<li>About
</li>
<li>Getting Started
</li>
</ul>
</nav>
</header>
</div>
As #Paulie_D commented, the brown in the top border of your anchor tag is the point of intersection between your top green and surrounding brown border. Because the background color of your li is already brown, I'd recommend removing the brown border like so:
body {
font-family: 'Roboto', sans-serif;
font-weight: 300;
background-color: #C8E6C9;
margin: 0;
padding: 0;
}
.container {
margin: 0 10% 0 10%;
}
header, ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #4CAF50;
}
h1 {
margin: 0;
border-bottom: 1px solid #FFFFFF;
font-family: 'Roboto', sans-serif;
font-weight: 400;
}
li {
float: left;
margin: 0 0 0 0;
}
h1, li a {
display: block;
color: #FFFFFF;
padding: 14px 16px;
text-decoration: none;
border-top: 6px solid #4CAF50
}
h1 {
border: 2px solid #4CAF50;
}
/*link actions*/
li a.active {
background-color: #795548;
border-top: 6px solid #388E3C;
}
li a:hover {
background-color: #FDD835;
border: 2px solid #795548;
border-top: 6px solid #388E3C;
color: #795548;
}
li a.active:hover {
background-color: #FDD835;
border: 2px solid #795548;
border-top: 6px solid #388E3C;
}
a:first-child {
text-decoration: none;
color: #FFFFFF;
}
a:first-child:hover {
color: #795548;
}
<body>
<noscript>Please Use JavaScript you loser.</noscript>
<div class="container">
<header>
<nav>
<h1>My Website</h1>
<ul>
<li>Home</li>
<li>About</li>
<li>Getting Started</li>
</ul>
</nav>
</header>
</div>
</body>
Note: I also removed the fallback green border of your li to only apply to the h1.

How to remove top nav bar border

I have a top navigation bar that still has the white borders around. I would like to know how to remove them using css.
This is the css:
#nav {
width: 100%;
float: left;
margin: 0 0 3em 0;
padding: 0;
list-style: none;
background-color: #4c4c4c;
}
#nav li {
float: left;
}
#nav li a {
display: block;
padding: 8px 15px;
text-decoration: none;
font-weight: bold;
color: white;
border-right: 1px solid #ccc;
}
#nav li a:hover {
color: grey;
background-color: white;
}
This is the HTML:
<body>
<ul id="nav">
<li>About Us</li>
<li>Our Products</li>
<li>FAQs</li>
<li>Contact</li>
<li>Login</li>
</ul>
Thanks.
Not sure about the question. In #nav li a You are giving border-right: 1px solid #ccc; remove this and I can not see any border any more. Let me know in case you needed something else.
Change border-right: 1px solid #ccc; to border-right: 0px solid #ccc; .Hence,
#nav li a {
display: block;
padding: 8px 15px;
text-decoration: none;
font-weight: bold;
color: white;
border-right: 0px solid #ccc;
}
please check the below code and modify accordingly. The issue will be resolved.
#nav li a {
display: block;
padding: 8px 15px;
text-decoration: none;
font-weight: bold;
color: white;
}

active menu css not working

CSS
#menu2
{
background: black;
float: left;
list-style: none;
margin: 0;
padding: 0;
width: 220px;
}
#menu2 li
{
margin: 0;
padding: 0;
}
#menu2 a
{
border-bottom: 1px solid #393939;
color: #ccc;
display: block;
margin: 0;
padding: 9px 16px;
text-decoration: none;
}
#menu2 a:hover
{
background: black url("../images/select.png") left center no-repeat;
color: #fff;
padding: 9px 16px;
}
#menu2 a:active
{
background: red;
color: #fff;
padding: 9px 16px;
}
JQuery
<script type="text/javascript">
$(document).ready(function() {
$("#menu2 li a").click(function() {
$(".active").removeClass("active");
$(this).addClass('active');
});
});
</script>
HTML
<ul id="menu2">
<li>Home</li>
<li>About us</li>
<li>Contacts</li>
</ul>
Replace this #menu2 a:active into this #menu2 a.active
As like this
Replace this
#menu2 a:active
{
background: red;
color: #fff;
padding: 9px 16px;
}
into this
#menu2 a.active
{
background: red;
color: #fff;
padding: 9px 16px;
}
Demo
Active Navi More info

Extending the "trigger area" that activates the dropdown menu.

Currently, only when the mouseover occurs near the phone icon or the little arrow-up area, will the dropdown menu not disappear when you move your cursor down to click on the links in the dropdownmenu.
When someone mouses over from the word 'Contact', the dropdown menu disappears as soon as he moves the cursor. I want the dropdown menu to remain as user moves the cursor down from the word 'Contact' .
HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="style2.css" type="text/css" />
</head>
<body>
<div class="Navigation">
<div id="navbar">
<ul>
<li class="OP" id="OPM1"><img src="images/order.png" />Orders</li>
<li class="OP"><img src="images/contact.png" />Contact
<div class="extended">
<div class="arrow-up"></div>
<ul class="smallNav">
<li>+65-65553333</li>
<li>Facebook</li>
<li>Twitter</li>
<li>enquiry [at] foodstant [dot] com</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</body>
</html>
CSS:
.Navigation { background:background: rgb(246,248,249); /* Old browsers */
background: -moz-linear-gradient(top, rgba(246,248,249,1) 0%, rgba(229,235,238,1) 46%, rgba(215,222,227,1) 65%, rgba(245,247,249,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(246,248,249,1)), color-stop(46%,rgba(229,235,238,1)), color-stop(65%,rgba(215,222,227,1)), color-stop(100%,rgba(245,247,249,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,1) 46%,rgba(215,222,227,1) 65%,rgba(245,247,249,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,1) 46%,rgba(215,222,227,1) 65%,rgba(245,247,249,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,1) 46%,rgba(215,222,227,1) 65%,rgba(245,247,249,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(246,248,249,1) 0%,rgba(229,235,238,1) 46%,rgba(215,222,227,1) 65%,rgba(245,247,249,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f6f8f9', endColorstr='#f5f7f9',GradientType=0 ); /* IE6-9 */
border-top-left-radius: 10px;
border-bottom-left-radius:10px;
border-top-right-radius: 10px;
border-bottom-right-radius:10px;
box-shadow: -3px -5px 10px #888888;
font-size: 26px;
font-family: 'Conv_LITHOSPRO-REGULAR';
}
.Navigation ul li { position: relative; list-style: none; padding: 17px 10px; }
.Navigation ul li a { font-size: 26px; font-weight: bold; color: white; text-decoration: none; text-shadow: 0 1px 2px black; }
.Navigation ul li:hover { background: url(images/hover.png) repeat-x; height: 43px; -webkit-box-shadow: 0 0px 2px black inset; padding: 20px 9px; border-left: 1px solid #a4a4a4; border-right: 1px solid #a4a4a4;}
.Navigation ul li:hover { background: none; -webkit-box-shadow: none; -moz-box-shadow: none; height: auto; border: none; }
.arrow-up { width: 0; height: 0; border-left: 10px solid transparent; border-right: 10px solid transparent; border-bottom: 15px solid #6a6a63; position: absolute; left: 20px; top: -15px; }
.Navigation ul li .extended { position: absolute; top: 45px; left: 0; width: 220px; background: url(images/dropdownback.png); z-index: 1000; -moz-box-shadow: 0 0px 8px rgba(0,0,0,0.8); -webkit-box-shadow: 0 0px 8px rgba(0,0,0,0.8); box-shadow: 0 0 8px black; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; border: 1px solid white; display: none; color: white; }
.Navigation ul li .extended img { display: block; margin: 5px auto 15px auto; -webkit-box-reflect:below 0px -webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(0.8, transparent), to(rgba(255,255,255,0.5))); }
.Navigation ul li .extended a { font-size:14px;}
.Navigation ul li .extended h2, .Navigation ul li .ultraNav h2 { padding-top: 10px; padding-left: 10px; font-size: 16px; text-shadow: 0 1px 2px black; color: white; background: url(images/headerback.png) repeat-x; height: 20px; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; }
.Navigation ul li .extended span { padding-left: 10px; font-size: 11px; }
.Navigation ul li .extended ul.smallNav { border-top: 1px solid rgba(141,141,141,0.50); padding: 10px; height: 100px; }
.Navigation ul li .extended ul.smallNav li { width: 200px; padding: 0; line-height: 22px; font-weight: bold; background: url(images/linkback.png) no-repeat; }
.extended ul li {float:left;}
.Navigation ul li .extended ul.smallNav li:first-child { margin: 0; }
.Navigation ul li .extended ul.smallNav li:last-child { margin-bottom: 10px; }
.Navigation ul li:hover .extended { display: block; }
.Navigation ul li ul li:hover a { color: white; }
#navbar {
}
#navbar ul {
list-style-position:inside;
padding-top: 10px;
padding-bottom: 10px;
}
#navbar ul li {
display: inline;
padding:0 20px 0px 0px;
margin-bottom: 10px;
list-style-type:disc;
}
#navbar ul li.OP {
padding-left: 15px;
}
#navbar ul li.OP img {
vertical-align: middle;
}
#navbar li a:link {
color: #EF174A;
}
#navbar li a:visited {
color: #BF4100;
}
#navbar li a:hover {
color: black;
background-color:#D2D2D2;
border-radius: 10px;
}
#navbar li a:active {
color: #918FBC;
}
li a {
text-decoration:none;
}
#navbar ul li.OP a {
padding-left: 10px;
}
.Navigation ul li .extended ul.smallNav li a { color: #c7c7c7 !important; text-shadow: none !important; }
.Navigation ul li .extended ul.smallNav li a:hover { color: white !important;}
Wrap the arrow-up DIV with another DIV like this:
<div class="arrow-container"><div class="arrow-up"></div></div>
Then add the arrow-container style as:
.arrow-container { margin-top:-16px; height:16px; }

Drop-down menu with hovering parent item

I want simple drop-down menu. But I have one problem. I want when I hover over dropped items (drop-menu-items) my parent element (drop-menu-parent) to be colored with black, but it's in white. I can't explain it very well. You can see it here -> http://jsfiddle.net/YEyuP/
I think this is what you need : http://jsfiddle.net/YEyuP/6/
HTML:
<nav>
<ul id="cat-nav">
<li>About</li>
<li>Contact</li>
<li class="drop-menu-parent">
Portfolio
<ul class="drop-menu-items">
<li>Some other category</li>
<li>Some other category</li>
<li>Some other category</li>
<li>Some other category</li>
</ul>
</li>
<li>Testimonials</li>
<li>Browse Products</li>
<li>Support Forum</li>
</ul>
</nav>
​
CSS:
nav {
background: #000;
}
#cat-nav {
text-align: center;
background-color: #0f0609, #0f0609;
background-image: url(cat-nav-bg.jpg), url(cat-nav-bg-bottom.jpg);
background-repeat: no-repeat, repeat-y;
margin-top: -8px;
display: block;
}
#cat-nav:after {
content: " ";
display: block;
clear: both;
width: 81%;
padding-top: 8px;
margin: 0 auto;
background: url(teeth.png) repeat-x;
}
ul#cat-nav > li {
text-align: center;
display: inline-block;
}
#cat-nav a:link { color: #fff; text-decoration: none; padding: 10px; display: inline-block;}
#cat-nav a:hover { color: #fff; text-decoration: none; }
#cat-nav a:visited { color: #fff; text-decoration: none; }
#cat-nav a:active { color: #fff; text-decoration: none; }
ul .drop-menu-items {
position: absolute;
display: none;
background: #fff url(drop-menu-bg.png) bottom repeat-x;
-webkit-box-shadow: 0px 5px 5px #8f8f8f;
-moz-box-shadow: 0px 5px 5px #8f8f8f);
box-shadow: 0px 5px 5px #8f8f8f;
border-radius: 0 10px 10px 10px;
}
ul.drop-menu-items li{
background: url(drop-menu-bullet.png) no-repeat 5px center;
float: none;
position: relative;
color: #000;
padding: 5px 15px;
margin: 0 10px;
border-bottom: 1px dotted #cecece;
}
ul.drop-menu-items li:hover {
background: #f0f0f0 url(drop-menu-bullet.png) no-repeat 5px center;
}
.drop-menu-parent:hover .drop-menu-items {
display: block;
z-index: 1000;
}
#cat-nav > li:hover a{
color:#000;
}
ul#cat-nav li a:hover {
background: #fff;
border-radius: 5px;
/* padding-top: 5px; */
}
#cat-nav .drop-menu-items li a {
color: #000;
}
#cat-nav .drop-menu-items li:hover a {
text-decoration: underline;
background: none;
color: #000;
}
.drop-menu-parent:hover {
background: #fff;
background-color: #fff;
border-radius: 5px 5px 0 0;
}
​
explanation
What i have added is this :
#cat-nav > li:hover a{
color:#000;
}
'>' indicates a direct child...so the direct child of #cat-nav when hovered over will assign a black color to the tag.
You could have also written : #cat-nav .drop-menu-parent:hover > a { color:#000; }
And it would have worked just as well...Infact, this second bit is a better option.
Add:
ul#cat-nav li:hover a{
color: #000;
}
Not sure if I understood you right(?), but here's an example. Is this what you mean? jsFiddle
nav {
background: #000;
}
#cat-nav {
text-align: center;
background-color: #0f0609, #0f0609;
background-image: url(cat-nav-bg.jpg), url(cat-nav-bg-bottom.jpg);
background-repeat: no-repeat, repeat-y;
margin-top: -8px;
display: block;
}
#cat-nav:after {
content: " ";
display: block;
clear: both;
width: 81%;
padding-top: 8px;
margin: 0 auto;
background: url(teeth.png) repeat-x;
}
ul#cat-nav > li {
text-align: center;
display: inline-block;
}
#cat-nav a:link { color: #fff; text-decoration: none; padding: 10px; display: inline-block;}
#cat-nav a:hover { color: #fff; text-decoration: none; }
#cat-nav a:visited { color: #fff; text-decoration: none; }
#cat-nav a:active { color: #fff; text-decoration: none; }
ul .drop-menu-items {
position: absolute;
display: none;
background: #000 url(drop-menu-bg.png) bottom repeat-x;
-webkit-box-shadow: 0px 5px 5px #8f8f8f;
-moz-box-shadow: 0px 5px 5px #8f8f8f);
box-shadow: 0px 5px 5px #8f8f8f;
border-radius: 0 10px 10px 10px;
}
ul.drop-menu-items li{
background: url(drop-menu-bullet.png) no-repeat 5px center;
float: none;
position: relative;
color: #000;
padding: 5px 15px;
margin: 0 10px;
border-bottom: 1px dotted #cecece;
}
ul.drop-menu-items li:hover {
background: #000 url(drop-menu-bullet.png) no-repeat 5px center;
}
.drop-menu-parent:hover .drop-menu-items {
display: block;
z-index: 1000;
}
ul#cat-nav li a:hover {
background: #000;
border-radius: 5px;
color: #fff;
/* padding-top: 5px; */
}
#cat-nav .drop-menu-items li a {
color: #fff;
}
#cat-nav .drop-menu-items li:hover a {
text-decoration: underline;
background: none;
color: #fff;
}
.drop-menu-parent:hover {
background: #000;
background-color: #000;
border-radius: 5px 5px 0 0;
}
​

Resources