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
Vineel Aakash Koppolu
1,898 PointsOrder of code?
Is it mandatory to have all the code(CSS) in exact order as shown in the video? Because I changed the order and there is a disturbance in my page alignment.
2 Answers
allisong
10,414 PointsCSS order only matters if you are targeting a specific item more than once and changing that element. For example, you modify a <div> with a class of "title" and then modify it again a few lines below that. Hope this helps!
Tobias Helmrich
31,604 PointsHey Vineel,
that depends on whether an element's style will be overwritten or not. Due to the cascading nature of CSS styles will be overwritten if an element get's another value for a property that was already set before.
Here is a simple example: Here we have two elements, an anchor and a paragraph where we set the color, it doesn't matter in which order we write this because it's two different elements.
a {
color: blue;
}
p {
color: grey;
}
However if we're styling the paragraph element two times the latter one will overwrite the first one.
p {
color: grey;
}
p {
color: black;
}
In this case the paragraphs' color on the site will be black and not grey because the second rule overwrites the first one where the color is set to grey. This is a very simple example and the cascade can become quite complex at some points but I hope you can understand it better now! :)