a id= as aposed to a href= - css

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>

Related

My a:hover is not working for some reason

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.

CSS Nav bar current/active color link

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;
}

Dropdown menu: Submenu name is below the menu bar and not within the nav box

I've coded a css dropdown menu and cant seem to get the name "LOGOS" to stay within the green box when I hover over the word "Illustration". I've made the word 5em so I can see it. Cant get it to stay in the box...no control of it's position. Can you help?
Thanks,
T.
<div id="nav-bar-sm-cont">
<ul id="sm-nav">
<li id="home">HOME</li>
<li id="about">PROFILE</li>
<li id="illustration">ILLUSTRATION
<ul>
<li id="logos">LOGOS</li>
</ul>
</li>
<li id="billboards">BILLBOARDS</li>
<li id="six-mo">6 MO BREAKFAST</li>
<li id="cal">ARTSHOW</li>
<li id="church">CHURCH</li>
<li id="contact">CONTACT</li>
<li id="cat-ill">CAT ILLUSTRATION</li>
<li id="contact-cat">CONTACT CAT</li>
</ul>
</div>
<!--end nav bar sm container -->
/* START small NAV bar **************************/
#nav-bar-sm-cont { position: absolute;
width: 1000px;
height: 100px;
}
#sm-nav li { position: relative;
top: 30px;
left: 35px;
font-size: .6em;
line-height: 250%;
letter-spacing: 0.3em;
list-style-type: none;
float: left;
}
#sm-nav a:link{ text-decoration:none;
color:silver;
background-color:transparent;
padding: 5px 5px;
}
#sm-nav a:visited {text-decoration:none;
color: #9781B7;
padding: 5px 5px;
background-color: transparent;
}
#sm-nav a:hover {text-decoration:none;
color: #fff;
background-color:#a7d6d5;
padding: 5px 5px;
}
#sm-nav a:active {text-decoration:none;
color:#fff;
background-color: green;
padding: 5px 5px;
}
/*start drop down************************************/
#sm-nav li ul { position:relative;
list-style-type: none;
display: none;
}
#sm-nav li:hover ul { position: absolute;
background: green;
padding: 5px 5px;
display:block;
font-size: 5em;
width: 103px;
height: 10px;
}
/*end drop down*****************************************/
/* END small NAV BAR *****************************/
The problem is that your CSS for the li is affecting both the parent li and the child. To fix that just change:
#sm-nav li {
to
#sm-nav > li {
Now that CSS will only affect the parent li and you're free to adjust the CSS for the child however you want like this:
#sm-nav li:hover ul li { }
JSFiddle

How to add second level to a submenu in a dropdown navigation css

I have created the navigation menu listed below:
<div class="menu">
<ul>
<li>
<a href="index.php" target="_self" >Home</a>
</li>
<li>
<a href="preparation.php" target="_self" >Gallery</a>
<ul>
<li>
Storybooks
</li>
<li>
Preparation
</li>
<li>
Ceremony
</li>
<li>
Personal Shooting
</li>
<li>
First Dance
</li>
<li>
Details
</li>
</ul>
</li>
<li>
<a href="login.php" target="_self" >Customers</a>
</li>
<li>
<a href="about.php" target="_self" >About</a>
</li>
<li>
<a href="contact.php" target="_self" >Contact</a>
</li>
</ul>
</div>
The CSS for this menu at the moment is:
.menu {
margin: 0px;
padding: 0px;
font-family: "Times New Roman";
font-size: 14px;
font-weight: bold;
color: #6D6D6D;
}
.menu ul {
height: 26px;
list-style: none;
margin: 0;
padding: 0;
}
.menu li {
float: left;
padding: 0px;
}
.menu li a {
color: #6D6D6D;
display: block;
font-weight: normal;
line-height: 26px;
margin: 0px;
padding: 0px 25px;
text-align: center;
text-decoration: none;
}
.menu li a:hover, .menu ul li:hover a {
background: #ca9875 url("menu_images/hover.gif") bottom center no-repeat;
color: #6D6D6D;
text-decoration: none;
}
.menu li ul {
/*background:#333333;*/
/*background: #B32267;*/
background: white;
display: none;
height: auto;
padding: 0px;
margin: 0px;
border: 0px;
position: absolute;
/*width: 225px;*/
width: 135px;
z-index: 200;
/*top:1em;
/*left:0;*/
}
.menu li:hover ul {
display: block;
}
.menu li li {
background: url('menu_images/sub_sep.gif') bottom left no-repeat;
display: block;
float: none;
margin: 0px;
padding: 0px;
/*width: 225px;*/
width: 135px;
}
.menu li:hover li a {
background: none;
}
.menu li ul a {
display: block;
height: 26px;
font-size: 13px;
font-style: normal;
margin: 0px;
padding: 0px 10px 0px 15px;
text-align: left;
}
.menu li ul a:hover, .menu li ul li:hover a {
background: #ca9875 url('menu_images/hover_sub.gif') center left no-repeat;
border: 0px;
color: #ffffff;
text-decoration: none;
}
.menu p {
clear: left;
}
I would like to know if there is a way to add second-level submenu to the category "Storybooks"? What i mean is that I would like to view another submenu in the right while i hover the mouse over the "Storybooks". Is this possible with css?
Appreciate any help, thanks.
I edited your code above to make it work, see http://jsfiddle.net/BVvc6/1/ for the new code.
Note: I added two menu points below Storybooks called Storybook 1 and Storybook 2. CSS is added to the bottom of the existing code (nothing altered above).
EDIT: You should clear up your CSS code a bit, e.g. use CSS selectors like > to match specific DOM levels.

How to set child unordered list position?

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;
}

Resources