Snow_Mac Snow_Mac -4 years ago 85
CSS Question

CSS which takes precedence, inline or the class?

My website has a stylesheet defined in the header as style.css with a selector:

.myClass {background:#000;}

Now my div looks like:

<div class="myClass" style="background:#fff;"> &nbsp; </div>

Which one has priority, the inline or the class?

Answer Source

Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number four has the highest priority:

1.Browser default 2. External style sheet 3. Internal style sheet (in the head section) 4.Inline style (inside an HTML element)

Source: w3schools

W3schools explains a lot about CSS and also goes through and shows examples of most things you can do with CSS. Always a good resource if you have questions about something.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download