Solved

Applying multiple styles to one TD element

Posted on 2004-08-06
11
768 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
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

856 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