Darren Riches
Darren Riches

Reputation: 149

How can I create two li styles?

I have created a li ul menu and it's working perfectly. However, I want the last li in the code below to have a different background.

I've tried adding style="background-color:#F00" to the li in question, but it doesn't work.

Does anyone know how this can be done?

Thanks in advance,

<!DOCTYPE html>

<html>

<head>

<style type="text/css">

#cssmenu {
background:#a8ac9d;
width: 270PX;
}
#cssmenu > ul {
padding:1px 0;
margin:0px;
list-style:none;
width:270px;
height:21px;
font:normal 8pt verdana, arial, helvetica;
}
#cssmenu > ul li {
margin:0;
padding:0;
display:block;
float:left;
position:relative;
width:270px;
}
#cssmenu > ul li a:link, #cssmenu > ul li a:visited {
padding:4px 0;
display:block;
text-align:center;
text-decoration:none;
background:#a8ac9d;
color:#ffffff;
width:270px;
height:13px;
}
#cssmenu > ul li:hover a, #cssmenu > ul li a:hover, #cssmenu > ul li a:active {
padding:4px 0;
display:block;
text-align:center;
text-decoration:none;
background:#a8ac9d;
color:#ffffff;
width:270px;
height:13px;
}
#cssmenu > ul li ul {
margin:0;
padding:0px 0px 0;
list-style:none;
display:none;
background:#a8ac9d;
width:270px;
position:absolute;
top:21px;
left:0px;
}
#cssmenu > ul li:hover ul {
display:block;
width: 270PX;
}
#cssmenu > ul li ul li {
width:146px;
clear:left;
width:270px;
}
#cssmenu > ul li ul li a:link, #cssmenu > ul li ul li a:visited {
clear:left;
padding:4px 0;
width:270px;
position:relative;
z-index:1000;
}
#cssmenu > ul li ul li:hover a, #cssmenu > ul li ul li a:active, #cssmenu > ul li ul li a:hover {
clear:left;
background:#a8ac9d;
padding:4px 0;
width:270px;
position:relative;
z-index:1000;
}
</style>

</head>

<body>

<div id='cssmenu'>
<ul>
<li><a href='#'><span>Products</span></a>
<ul>
<li><a href='#'><span>Product 1</span></a></li>
<li style="background-color="#F00"><a href='#'>Product 2</a></li>
</ul>
</li>
</ul>
</div>

</body>

</html>

Upvotes: 0

Views: 262

Answers (3)

Dukeland
Dukeland

Reputation: 146

I didn't read in detail but at first glance, this line is the problem.

<li style="background-color="#F00"><a href='#'>Product 2</a></li>

Should be

<li style="background-color:#F00"><a href='#'>Product 2</a></li>

Edit: The code above does not work!!! It's because the element having the background color is . So you should change to this.

<li><a href='#' style="background-color:#F00">Product 2</a></li>

Upvotes: 2

Sowmya
Sowmya

Reputation: 26969

You need to write it for the a tag which is inside the li

Add this

#cssmenu ul li ul li:last-child a{
background:red
}

DEMO

Upvotes: 2

Kangkan
Kangkan

Reputation: 15571

When you write style attribute, the syntax to be followed is as in the css. you have written style="background-color="#F00" and it should be style="background-color: #F00"

Upvotes: 0

Related Questions