Well this question came after this one
The reasons are pretty much the same, to keep the stuff cleaner, how bad is it to call (being sure the css doesn't collide with overwriting tags)
To put <link rel="stylesheet" type="text/css" href="mycss.css">
in the middle of the body? (if it works)
So that in some cases I could have specific css for a specific module include.
CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section.
As CSS is not document content, it should be in the head. Also every other Web developer will expect to see it there, so don't confuse things by putting it in the body, even if it works!
One solution is put all the css file in root-directory/css , while quite a few websites use hierarchical directory like '/skin' '/global' etc.
You want multiple CSS files because your sanity is a terrible thing to waste. At the same time, it's better to have a single, large file. The solution is to have some mechanism that combines the multiple files in to a single file.
While theoretically you should only put CSS in the head
tag, in practice this is often not feasible, or just not worth the pain.
If you do put it in the middle of the document, one of the following two things will happen:
The browser will start loading (and displaying) your page, and then once it gets up to the new CSS, the existing content will change or move around
The browser will just take a bit longer to display your content.
The first thing seems bad, but it generally isn't a problem. Well it hasn't been for me anyway, because 9 times out of 10, if you're putting CSS in the middle of the page, the CSS is only "built for" the content that comes after it, and doesn't affect the things above it, so they won't move or change anyway
So to answer your question of "how bad is it", I'd say - not bad at all, just be wary of writing CSS that affects parts of the page that got loaded before the CSS file did.
<link>
is only permitted in the <head>
section of a document: Document relationships: the LINK element
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With