Jump to content

How To Apply A Class To All The Same Tags In A Page?


bigbug

Recommended Posts

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...