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

Why does the link to the CSS file come after the text of the title instead of nearer the top?

It seems like, if one file is styling another, then it would be linked before any actual presentation element (text, img, video, etc.) were required to be read. Granted, my understanding of all of this is very limited.

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Ideally, you'll want one CSS file to style the entire website, which you can link to in a tag like this.

<link rel="stylesheet" type="text/css" href="style.css" />

In terms of one style overriding another style, this is down to the cascading nature of CSS.

So let's say for example you did have another stylesheet in your website containing the same styles in both.

<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="second_style.css" />

and you had paragraph style for example, the style in second_style.css would override what was in the declaration for style.css.

In addition types of styles in one file vary in terms of specificity. For example an ID style has more specificity than a class style. It selects a single element so is higher in the order of preference.

Hope that helps! :)

Jonathan - I was confused, my question was in reference to the "title tags", which I had forgotten refer to the text in the web tab and what goes to the screen reader. I was unable to update my question to clarify my mistake. I appreciate the thorough answer though.