Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to declare multiple CSS classes?

Status
Not open for further replies.

joelwenzel

Programmer
Jun 28, 2002
448
Is it possible to declare multiple CSS classes?

<span class=one class=2> sdfasdf</span> ?
 
no not currently. Eventually you will be able to do it when CSS2 is supported in browsers with the following syntax :

class=&quot;classOne classTwo&quot;

BTW a class name should always start with a letter. I imagine your class name 2 is just for example purpose but in case it wasn't I thought I would mention it. Gary Haran
 
Or maybe something like this is possible

<style type=&quot;text/css&quot;>

.one
{
attributes
}

.one.two
{
attributes
}

<span class=two>asdfasdf</span>

whereby calling two, I could have both attributes from class one and two. Is this possible?

</style>
 
no that shouldn't work. that syntax is use when you want an elemental selector to have other features. however you could cheat the system using this example :

<html>
<head>
<title>check all</title>
<style>
a /* elemental selector */
{
color: red ;
}

a.two /* class selector on a element */
{
font-weight: bold ;
}
</style>
</head>
<body>

<a href=&quot;test.html&quot;>this is a test</a>
<a href=&quot;test.html&quot;>this is a test</a>
<a href=&quot;test.html&quot;>this is a test</a>
<a href=&quot;test.html&quot; class=two>this is a test</a>
<a href=&quot;test.html&quot;>this is a test</a>
<a href=&quot;test.html&quot;>this is a test</a>
</body>
</html> Gary Haran
 
Yuo can do what you want by combining CSS classes and IDs. Here's an example:

.class1 { font: 10pt arial,sans-serif; color: black }
#green1 { color: green }
#bold1 { font-weight: bold }


then in html body:
<p class=class1>this is black sans-serif text
<span id=green1>but this is green (color declaration in ID overrides the one from class)</span>.
</p>

<p class=class1 id=bold1>this is black and bold sans-serif text because it uses a combination of css class and id.
</p>

good luck
 
Thanks. I will try the id/class deal but I will be happy once css2 is fully supported
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top