Forum Moderators: not2easy

Message Too Old, No Replies

styling links in alternating backgrounds

the customer wants it this way

         

Baruch Menachem

10:37 pm on Sep 26, 2009 (gmt 0)

10+ Year Member



The customer wants a set of links inside alternating backgrounds. The back ground colors he wants are red and yellow. Links look awful with the red back ground, and he wants white links.

I am trying this

.t0
{
background-color: #ff3300 ;
font-size :12pt;
margin-left :20px;


}
.t1
{
background-color: #ffff00 ;
font-size :12pt;
margin-left :20px;

}
.t0.a
{
color:white;

}

but it is not working. I want to style the color of the link dependent on the color of the back ground. Is that possible.

the backgrounds alternate with a ternary operator in php. Would it be better just to hand code that?

D_Blackwell

12:05 am on Sep 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Without the HTML, markup is a complete stab in the dark.

However, as understand I the question, ...The back ground colors he wants are red and yellow. Links look awful with the red back ground, and he wants white links., it should be no problem at all. In the sample below, I have put the likeliest cause of the problem in blue.

Yellow background-color: with white color: is even worse, so you may not intend that, but you can probably see how to make the swap or edit now.

This declaration is looking for trouble:
.t0.a
{
color:white;

}

Better is:
.t0 a

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
.t0 {
background-color: #f30;
font-size: 12pt;
margin-left: 20px;
}

.t1
{
background-color: #ff0;
font-size: 12pt;
margin-left: 20px;
}

.t0 a, .t1 a {
color: #fff;
}

</style>
</head>
<body>
<div>
<p class="t0">
<a href="www.example.com">
LINK
</a>
</p>
<p class="t1">
<a href="www.example.com">
LINK
</a>
</p>
</div>
<!--##########
The customer wants a set of links inside alternating backgrounds. The back ground colors he wants are red and yellow. Links look awful with the red back ground, and he wants white links.

but it is not working. I want to style the color of the link dependent on the color of the back ground. Is that possible.

the backgrounds alternate with a ternary operator in php. Would it be better just to hand code that?
-->
</body>
</html>

swa66

11:13 am on Sep 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



CSS3 :nth-child(odd) and :nth-child(even) pseudo class selectors could do this in some browsers without needing to add classes all over in the place.
[webmasterworld.com...]

Actually it's possible to just add the odd or the even classes: you can change the normal style with a switch of the colors only, leading to more compact code in both html and css.