Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How bad is it to put a CSS include in the middle of the body? [closed]

Tags:

html

css

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.

like image 558
fmsf Avatar asked Feb 26 '09 00:02

fmsf


People also ask

Can CSS be included in body?

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.

Should CSS be in head or body?

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!

Where should CSS files be placed?

One solution is put all the css file in root-directory/css , while quite a few websites use hierarchical directory like '/skin' '/global' etc.

Is it bad to have multiple CSS stylesheets?

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.


2 Answers

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.

like image 163
Orion Edwards Avatar answered Sep 26 '22 08:09

Orion Edwards


<link> is only permitted in the <head> section of a document: Document relationships: the LINK element

like image 44
Chad Birch Avatar answered Sep 23 '22 08:09

Chad Birch