bigbug Posted February 3, 2009 Share Posted February 3, 2009 For example, I want to apply "class_1" to all <TD> tags in a page, instead of typing <TD CLASS="class_1">, is there a better way like <style>TD{class=class_1;}</style> (Yes I know that syntax is not right) Link to comment Share on other sites More sharing options...
shadowayex Posted February 3, 2009 Share Posted February 3, 2009 If you want something to effect all of the tags on the page, don't use a class at all: td {formatting you want} That will effect every td on the page. Link to comment Share on other sites More sharing options...
Enthusiastic Student Posted February 3, 2009 Share Posted February 3, 2009 Hi BigbugYou can either generate the tags dynamically with e.g. php or if all you need is to apply formatting to all the tags within a know place then use: a.reallyCoolLink span{ float: left; background-color: #0e0e0e;} This will cause all the <span> tags within the <a class="reallyCoolLink"> tag to float left and have that background color.Hope it helpsEnthusiastic Student Link to comment Share on other sites More sharing options...
jlhaslip Posted February 3, 2009 Share Posted February 3, 2009 Spans are in-line elements, so float is a poor example to use since they will be floated left by default, I believe. Link to comment Share on other sites More sharing options...
Jerry62704 Posted February 3, 2009 Share Posted February 3, 2009 Hi BigbugYou can either generate the tags dynamically with e.g. php or if all you need is to apply formatting to all the tags within a know place then use:a.reallyCoolLink span{ float: left; background-color: #0e0e0e;} This will cause all the <span> tags within the <a class="reallyCoolLink"> tag to float left and have that background color.Hope it helpsEnthusiastic Student You can't float a span unless you turn that span into a block element. Then you have a block so it wouldn't sit within something like a line unless you turned it into an inline element - which is what you started with.Ragae has the right idea. Just apply your styling to the selector (TD in this case). Link to comment Share on other sites More sharing options...
Enthusiastic Student Posted February 3, 2009 Share Posted February 3, 2009 You guys are right it was not a well thought out example.ragae's solution will definetly work. My intention was to show how you could style all tags within an element. This could be useful if the same tags were used elsewhere on the site, but shouldn't be formatted the same way. A better example: div.rightMenu span{ color: #3fff00; background-color: #0e0e0e;} This will cause all the <span> tags within the <div class="rightMenu"> tag to have an (almost) black background color and green (harlequin) text. This could be used in a right-side menu.Hope it helpsEnthusiastic Student Link to comment Share on other sites More sharing options...
jeffman Posted February 3, 2009 Share Posted February 3, 2009 So a better illustration for the original question would be this: td { background-color: #000;}table.horses td { color: #faa;} So all <td> elements have a black background, but only the <td> elements inside <table class="horses"> have pink text. Link to comment Share on other sites More sharing options...
bigbug Posted February 4, 2009 Author Share Posted February 4, 2009 The problem of ragae's solution is that, if the style for all <TD> need to be change, the changes have to be made in every single page.Deirdre's Dad's solution works for <TD>, but if the tag is other type, I need to work in different way.Probably server side script is a better solution.Thanks for all replies. Link to comment Share on other sites More sharing options...
Jerry62704 Posted February 4, 2009 Share Posted February 4, 2009 The problem of ragae's solution is that, if the style for all <TD> need to be change, the changes have to be made in every single page.Deirdre's Dad's solution works for <TD>, but if the tag is other type, I need to work in different way.Probably server side script is a better solution.Thanks for all replies.You didn't have a link so we can't look at the real page, but you will want to have a css solution and that will require every page to have that css file on it. That's what we all do. Then if you want to change something like all <td> tags having red text, you only change the one css file and every page will have red text for <td> elements.As already mentioned, you can further localize it by saying all <td> elements inside a class of "myClass" have blue text and it will only affect those exact cases. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.