Solved

Applying multiple styles to one TD element

Posted on 2004-08-06
11
751 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
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:ycomp
Comment Utility
CSS 1 limitation I mean
0
 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
http:#11739958

Perfect.
0
 
LVL 2

Expert Comment

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

Expert Comment

by:Eternal_Student
Comment Utility
thats interesting.
0
 

Expert Comment

by:NanZhong
Comment Utility
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_
Comment Utility
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
Comment Utility
yes 2 class names works. I just thought it was illegal for some reason. IDs are not a solution for me.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now