Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Transitions and Transforms Getting Started with CSS Transforms Combining Transforms

Why does code at the bottom of the stylesheet affect the top? I thought that top code overruled identical bottom code.

Hey,

In this vid, Guil discusses how if you create conflicting CSS rules for the same element (in this case the image element) at the top and bottom of your stylesheet, then the bottom rule will override the top rule. However I recall being taught that, in these scenarios with Cascading Style Sheets, the top rule overrides the bottom rule.

Is this specific to the transform property?

Thanks -

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey there,

The Cascading part of CSS applies to any and all CSS.

The rules Cascade down and are 'executed' in that order (Top to Bottom... like a waterfall). So one at the top will be applied, but if there is another one after that for the same selector, it will overwrite the previous, and so on until the end of the Sheet. This is why Media Queries should always go at the end of the Sheet.
Additionally, if you have multiple sheets, the Cascading also applies. A rule in the first sheet loaded will be overwritten by the same rule in a sheet loaded after that.

Hope that helps clear things up. :)

:dizzy: