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 trialja5on
10,338 PointsHi, how should i layout CSS data?
Within any CSS3 file how should i lay it out? Should i have all IDs at top of the page or classes? Should each selector try to be positioned in order of the tags they are created from in html?
I generally start with the import then body selector then head then h1..h2 etc but i think things get messy the further i go...
Thanks for any suggestions..
1 Answer
William Ray Noble
22,190 PointsI'm not sure there is "best practice" on this issue. Generally I will group things by media query first and then (depending upon the size of the file) will group things either by id vs class or sections of a webpage.
Ross King
20,704 PointsRoss King
20,704 PointsHi jasonj7 ,
I'm not adding this as an answer as I don't really think there is going to be a clear cut answer for this.
I don't think you should worry about the order of IDs and classes as the cascading nature of stylesheets will most likely dictate where you have to do them.
When I started getting into CSS I wrote my own cheat sheet to keep my order similar to what you do e.g. Core Styles like body, headers, paragraphs and so on.
When you get more into CSS and SCSS later down the track the files can be broken up into smaller pieces making it much easier to maintain.
In my opinion it's better to keep going with the content instead of getting too concerned with the best structure as you will always learn new skills and look at your old work as a "what was I thinking" moment.