First homepage. Nav bar color for current page isn't working. Suggestions? CSS below. Thanks.
HTML
<ul class="nav">
<li>HOME</li>
<li>PRODUCTS</li>
<li>STAFF</li>
<li>LINKS</li>
<li>CONTACT</li>
</ul>
CSS
.nav{
border:1px solid #ccc;
border-width:1px 0;
list-style:none;
margin:20;
padding:0;
text-align:center;
font-family:sans-serif;
}
.nav li{
display:inline-block;
color:#493D26;
font-size: 15px;
font-family:sans-serif;
}
.nav a{
display:inline-block;
border-width:1px 0;
padding:15px;
text-decoration:none;
color:#493D26;
font-size: 17px;
font-style:bold;
text-transform:capitalize;
}
ul.nav a:hover{
color: #6CBB3C;
}
ul.nav a:current{
color: #6CBB3C;
}
You can use this css code also.
a:active : when you click on the link and hold it (active!).
a:visited : when the link has already been visited.
If you want the link corresponding to current page to be highlighted, you can define some specific style to the link -
ul.nav a:visited {
color: #6CBB3C;
}
Add this new class only to the corresponding li (link), either on server-side or on client-side (using javascript).
check the snippet..
.nav {
border: 1px solid #ccc;
border-width: 1px 0;
list-style: none;
margin: 20;
padding: 0;
text-align: center;
font-family: sans-serif;
}
.nav li {
display: inline-block;
color: #493D26;
font-size: 15px;
font-family: sans-serif;
}
.nav a {
display: inline-block;
border-width: 1px 0;
padding: 15px;
text-decoration: none;
color: #493D26;
font-size: 17px;
font-style: bold;
text-transform: capitalize;
}
ul.nav a:hover {
color: #6CBB3C;
}
ul.nav a:visited {
color: #6CBB3C;
}
<ul class="nav">
<li>HOME
</li>
<li>PRODUCTS
</li>
<li>STAFF
</li>
<li>LINKS
</li>
<li>CONTACT
</li>
</ul>
Oh dear..
Try .nav ul instead of ul.nav :)
You can use jQuery trick:
You should add jQuery library file fist:
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("ul.nav li a").each(function()
{
if(this.href==window.location.href)
{
$(this).addClass('current');
$(this).removeAttr('href');
}
});
});
</script>
and add this css:
ul.nav a.current{
color: #6CBB3C;
}
Related
I've a nicely layed out unlisted list with links using <a href="">, but when I add one link that requires <a id=""> the CSS ignores it.
As CSS only defines the attributes using li a:link{}, how do I get it to recognise the the id= too?
The id=swishLink is used a number of times throughout the site, so I cant really make any changes to swishyLink attributes.
I've tried the <div id=> option, but it means I have to create a CSS rule for each list item.
li:first-child a:link{
text-decoration: none;
border-top-right-radius: 2em;
border-top-left-radius: 2em;
}
li{
list-style-type: none;
text-decoration: none;
border: 2px solid white
}
li a:link{
text-decoration: none;
list-style-type: none;
width: 200px;
height:auto;
padding: 20px;
display: list-item;
background: #eefbe7;
font-family: Arial Rounded MT Bold,Helvetica Rounded,Arial,sans-serif;
text-align: center;
color: green;
}
li a:visited{
color: green;
}
li a:active{
color:purple;
}
li:last-child a:link{
border-bottom-right-radius: 2em;
border-bottom-left-radius: 2em;
}
/*
Change the link color on hover */
li a:hover {
text-decoration: none;
background: green;
color: white;
}
<ul>
<li>
One
</li>
<li>
<a id='swishyLink'> Two </a>
</li>
<li>
Three
</li>
<li>
Four
</li>
<li>
five
</li>
</ul>
If you want your CSS to also apply to <a> tags that aren't links, you shouldn't tell it to only apply to links.
It sounds like you don't want :link.
a:link is backfiring on you. Just use li a
li:first-child a{
text-decoration: none;
border-top-right-radius: 2em;
border-top-left-radius: 2em;
}
li{
list-style-type: none;
text-decoration: none;
border: 2px solid white
}
li a{
text-decoration: none;
list-style-type: none;
width: 200px;
height:auto;
padding: 20px;
display: list-item;
background: #eefbe7;
font-family: Arial Rounded MT Bold,Helvetica Rounded,Arial,sans-serif;
text-align: center;
color: green;
}
li a:visited{
color: green;
}
li a:active{
color:purple;
}
li:last-child a{
border-bottom-right-radius: 2em;
border-bottom-left-radius: 2em;
}
/*
Change the link color on hover */
li a:hover {
text-decoration: none;
background: green;
color: white;
}
<ul>
<li>
One
</li>
<li>
<a id='swishyLink'> Two </a>
</li>
<li>
Three
</li>
<li>
Four
</li>
<li>
five
</li>
</ul>
Not sure why it's not working, but here's my code.
.tm-nav ul li{
display: inline-block;
margin-top: 20px;}
.tm-nav ul li a {
padding: 10px 20px;
text-decoration: none;
font-family: Trebuchet MS;
font-size: 22px;
margin-left: 50px;
color: #8e7e6b;
}
.tm-nav a:hover: {
color: black;}
And here is my HTML:
<nav class="tm-nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Products</li>
<li>Privacy</li>
</ul>
</nav>
Whenever, I hover over my navigation links, they don't change color, even adding text-decoration: underline under a:hover does not take effect.
.tm-nav a:hover: {
color: black;}
should be
.tm-nav a:hover {
color: black;}
you have an extra colon sitting on ".tm-nav a:hover {}"
I removed the colon and tried it on my computer and it worked.
Here I have a working nav bar with a drop down menu. However I want two different hover effects on both the main nav bar and a different one for the drop down menu, I already have the main nav bar working with a hover effect by adding the below CSS code.
#nav_bar a:hover {
background:#8c1b1f;
padding-bottom:13px;
padding-top:17px;
padding-left:10px;
padding-right:10px;
}
I simply need a way of adding a separate hover effect to the drop down menu
You need to use CSS here this way:
#nav_bar>ul>li>a:hover {
//styles here for main menu hover
}
#nav_bar>ul>li>ul>li>a:hover {
//styles here for dropdown menu hover
}
So your CSS for the main menu hover will become:
#nav_bar>ul>li>a:hover {
background:#8c1b1f;
padding-bottom:13px;
padding-top:17px;
padding-left:10px;
padding-right:10px;
}
And you can use the following code to specify CSS for the dropdown menu hover:
#nav_bar>ul>li>ul>li>a:hover {
//styles here for dropdown menu hover
}
#nav_bar {
background-color: #a22b2f;
padding: 10px;
box-shadow: 0px 2px 10px;
}
#nav_bar ul {
text-align: center;
padding-left: 0px;
}
#nav_bar ul li {
display: inline-block;
}
#nav_bar ul li a {
color: white;
font-family: Arial;
text-decoration: none;
font-weight: bold;
padding: 15px;
}
#nav_bar ul li ul {
display: none;
}
#nav_bar ul li:hover ul {
display: block;
position: absolute;
padding: 0px;
background: white;
padding: 10px;
border: 1px solid black;
}
#nav_bar ul li:hover ul li {
display: block;
}
#nav_bar ul li:hover ul li a {
color: black;
}
#nav_bar>ul>li>a:hover {
color: blue;
background: #fff;
}
#nav_bar>ul>li>ul>li>a:hover {
color: red;
background: #000;
}
<div id="nav_bar">
<ul>
<li>HOME
</li>
<li>STATUS
</li>
<li>INFO
</li>
<li>GAMEMODES
<ul>
<li>GAMEMODE - SURVIVAL
</li>
<li>GAMEMODE - PURE-PVP
</li>
<li>GAMEMODE - GAMESWORLD
</li>
</ul>
</li>
<li>RULES
</li>
<li>VOTE
</li>
</ul>
</div>
I have a JS rollover switch, but when I click down on the link, the orange color doesn't stay, it reverts back to grey. What am I missing? Here is my code (orange is color: #f7931d):
CSS:
#content-slider {
padding-top:5px;
height: 240px;
width: 359px;
padding-left: 52px;
font-family: 'Century Gothic';
font-size: 11px;
color: #BBBDC0;
display:inline-block;
padding-bottom:25px;
overflow: hidden;
}
#content-slider-inside {
list-style: none;
height: 240px;
overflow:hidden;
overflow-y: hidden;
}
#content-slider-inside li {
height: 340px;
width: 359px;
font-family: 'Century Gothic';
font-size: 11px;
color: #BBBDC0;
display:inline-block;
padding-bottom:25px;
}
#navigation {
font-family: 'Century Gothic';
font-size: 14px;
color: #BBBDC0;
display: inline-block;
width: 940px;
height: 18px;
text-transform: uppercase;
padding-left: 45px;
padding-top: 20px;
padding-bottom:10px;
overflow: hidden;
white-space: nowrap;
text-decoration: none;
}
#navigation li {
color:#bbbdc0;
display:inline-block;
padding:5px;
text-decoration: none;
}
#navigation li a, #navigation li a:link, #navigation li a:visited {
color:#bbbdc0;
display:inline-block;
text-decoration: none;
}
#navigation li a.selected, #navigation li a.selected:link, #navigation li a.selected:visited, #navigation li a.selected:active {
color:#f7931d;
display:inline-block;
text-decoration: none;
}
#navigation li a:hover, #navigation li a:focus, #navigation li a:active, #navigation li a:focus:active {
display:inline-block;
text-decoration: none;
color:#f7931d;
}
HTML:
<ul id="navigation">
<li>overview</li>
<li>features</li>
<li>resume management</li>
<li>financials</li>
<li>expense tracking</li>
<li>search</li>
</ul>
Then the rest is basically just tags and anchors for when you click on the link.
<div id="content-slider">
<ul id="content-slider-inside">
<li id="overview">
text
</li>
<li id="features">
text
</li>
<li id="resumemanagement">
text
</li>
<li id="financials">
text
</li>
<li id="tracking">
text
</li>
<li id="search">
text
</li>
</ul>
</div>
It sounds like you are asking how to keep the menu item highlighted if its the current page. I discovered this handy little jQuery snippet on Stack Overflow a while ago, so I apologize that it is not attributed correctly. If someone recognizes this, please let me know and I will update with credits!
<script>
$(document).ready(function(){
var url = window.location.href.substr(window.location.href.lastIndexOf("/") + 1);
$('[href$="'+url+'"]').parent().addClass("nav-active"); //replace nav-active class with your preferred highlighting class-- in this case the orange color.
});
</script>
Basically it reads the browser URL, and if the end of the URL matches a menu item, it will keep it highlighted.
I have a nav bar with children unordered lists nested under the main navbar items. My problem is on the inner list, when I position absolute, the inner list is centered to the page, and when I position relative, it is positioning inline with the parent list.
I'm trying to get the first child item to line up directly under it's parent.
/* OUTER LIST STYLING */
div#navbar2 {
position:relative;
width: 100%;
border-top: solid #000 1px;
border-bottom: solid #546F8B 1px;
background-color: #546F8B;
}
div#navbar2 ul#navbar {
padding: 0;
margin: 10px 0;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
letter-spacing:1px;
color: #FFF;
white-space: nowrap;
}
div#navbar2 ul#navbar li {
margin: 0 2px;
list-style-type: none;
display: inline;
}
div#navbar2 li a {
text-decoration: none;
color: #fff;
padding: 10px 10px;
}
div#navbar2 li a:link {
color: #FFF:
}
div#navbar2 li a:visited {
color: #ffffff;
}
div#navbar2 li a:hover {
color: #000;
background-color: #FDFFC9;
}
/* INNER LIST STYLING */
div#navbar2 ul#navbar li ul.innerlist{
display: none;
color:#000;
}
div#navbar2 ul#navbar li ul.innerlist li{
color:#000;
}
div#navbar2 ul#navbar li:hover ul.innerlist {
position: absolute;
display: inline;
left: 0;
width: 100%;
margin: 40px 0 0px 0px;
padding: 0px;
color:#000;
}
div#navbar2 li.innerlist a {
text-decoration: none;
color: #000;
padding: 10px 10px;
}
div#navbar2 li.innerlist a:link {
color: #000:
}
div#navbar2 li.innerlist a:visited {
color: #000;
}
div#navbar2 li.innerlist a:hover {
color: #000;
background-color: #FDFFC9;
}
And my html:
<div id="navbar2">
<ul id="navbar">
<li id="index">About Rattletree</li>
<li id="upcomingshows">Calendar</li>
<li id="booking">Contact
<ul class="innerlist">
<li class="innerlist">Booking</li>
<li class="innerlist">press</li>
</ul>
</li>
<li id="instruments">The Band
<ul class="innerlist">
<li class="innerlist">The Instruments</li>
<li class="innerlist">The Players</li>
</ul>
</li>
<li id="classes">Sights & Sounds
<ul class="innerlist">
<li class="innerlist">Listen</li>
<li class="innerlist">photos</li>
<li class="innerlist">video</li>
</ul>
</li>
<li id"classes">Workshops & Classes</li>
</ul>
</div>
Thanks for any help!
If you set the #navbar > li {position: relative;} and the ul.innerlist {position: absolute; } then it, and its descendant li elements, will be positioned in relation to the #navbar > lis instead of the page.
If I understood correctly what do you want, just add this to your CSS
#navbar .innerlist {
display: block;
margin-left: 0px;
padding-left: 0px;
}