Solved

Applying multiple styles to one TD element

Posted on 2004-08-06
11
773 Views
Last Modified: 2011-04-14
First off, this might sound like a strange question but bear in mind that the HTML is being dynamically generated and this is why I need to do it this way...

I have TD elements e.g. <TD class=format1>

The problem is that my TD.format1 style does not define any borders, just fonts and colors and indenting and such. I do not want to put border information in the format1 style.

I also want to apply borders to the TD.

Right now I am doing it this way: <TD class=format1 style='border-left: solid 1pt #3366ff; border-right: solid 2pt #66DDFF; border-top: dotted 3pt #FFCCEE;'>

as you can see this is very verbose... if I'm going to have many tens or hundreds of thousands of TDs then this adds much size to the file.

My understanding is that CSS does not allow something like this: class=format1,border1 . If it did support this then that would be ideal since I have a limited number of border styles and can construct a <STYLE>...</STYLE> listing all of them.

Can anyone think of a way to do what I want to do in a less verbose manner?
0
Comment
Question by:ycomp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 500 total points
ID: 11739958
Hi

Actually it is allowed: For example,

<style type="text/css">
.border1 {border:2px solid red;}
.format1 {font-size:24pt;}
</style>

<td class="format1 border1">HEHEHEHEHEHE</td>

Regards,
Zyloch
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11739965
P.S. And I owe knowing this all to Sean. I say thanks to the almighty one who knows 200+ times more than I in CSS and layout

Regards
0
 

Author Comment

by:ycomp
ID: 11739973
for some reason I thought I read somewhere it wasn't allowed. my memory is not the best though. perhaps maybe that was a CSS limitation?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ycomp
ID: 11739977
CSS 1 limitation I mean
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11740009
I'm not quite sure, sean will probably know, but it is official CSS as far as I know and is pretty widely supported:

http://www.w3.org/TR/html401/struct/global.html#adef-class
0
 
LVL 31

Expert Comment

by:seanpowell
ID: 11740057
http:#11739958

Perfect.
0
 
LVL 2

Expert Comment

by:Joakim_
ID: 11741134
This is allowed by W3C. Just go ahead and use it.
0
 
LVL 18

Expert Comment

by:Eternal_Student
ID: 11742540
thats interesting.
0
 

Expert Comment

by:NanZhong
ID: 11747865
Another way to do it would be giving the td both an id and a class.

Eg. <td id="id1" class="class1">

Then in the css just give #id1 and .class1 whatever styling you want.

Eg.

#id1 {border:2px solid red;}
.class1 {font-size:24pt;}
0
 
LVL 2

Expert Comment

by:Joakim_
ID: 11748436
That's a stupid solution. IDs have to be unique, and is meant to be used to give elements a unique ID. Either add two class names in the CLASS-tag, or make one class with the style.
0
 

Author Comment

by:ycomp
ID: 11749013
yes 2 class names works. I just thought it was illegal for some reason. IDs are not a solution for me.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question