Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS Class Overwrite 1

Status
Not open for further replies.

Ascalonian

Programmer
Jan 4, 2008
264
US
Say I have a <TD> element defined as:

Code:
    <td class="leftAlign rightAlign" id="testTD">
         Align Me!
    </td>

In leftAlign, I have it align the text to the left. The opposite in the right.

When I do this, the text is always left aligned. I would think rightAlign would overwrite this.

Am I understanding this wrong?

PS... The only way to make it right aligned is to put "! important" into the class directly.
 
Depends on what order you have them in in your CSS.

The lowest one will take precedence over the higher one.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
So in my example, rightAlign should have trumped leftAlign. Correct? That is what I expected to happen, but it is not happening.
 
Again depends on their position in your CSS.

for example:

CSS:
.class1{
border: 1px solid red;
}

.class2{
border: 2px solid blue;
}

HTML:
<div class="class1 class2"></div>

class2 being lower in the CS definition would get applied last, and override the border definition of class1.




even if i did:
<div class="class2 class1"></div>

class2 would still override class1 because its lower in the definition.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Each class is in a different file actually (don't ask why, haha). And rightAlign is imported after the leftAlign file. This just does not make sense.
 
Try adding a comma between your class names, see if that fixes it. It should make the second class overwrite the first one.

Code:
 <td class="leftAlign[red],[/red] rightAlign" id="testTD">



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
glad I could help.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top