tags:

views:

522

answers:

6

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.

+11  A: 

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

Chad Birch
+1  A: 

Stylesheets should be included in the head tag. Else you might get weird rendering 'flicks', depending on the browser. If you really want to use per module css stylesheets you should provide hooks to your template's head tag.

Tomh
+4  A: 

Honestly, if you are doing just once or a couple times in a big project, and that poor layout saves you days of recoding a new solution... go for it. You are right, it works.

You will get answers that it is bad because it isn't valid, because that just isn't right and if you do it too many times, I agree you should reconsider and fix the real problem. But once? I say go ahead; the web remains a pretty imperfect place.

Just don't apply to work with me, we don't put up with that crap here.

EDIT: Just looked at your other question and the site you were talking about. If this is related to your weekend project, do it the right way. Develop good habits early and often.

MrChrister
yeah it is related to my weekend project, having fun with it. The part non online is far more advanced than what's there. But it's not good yet to go online. Just having some fun with web development.
fmsf
+6  A: 

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.

Orion Edwards
A: 

It may work now, but as a link tag is only allowed in the head, there is no guarantee that it will work in the future; a browser update can lead to the css not being used any more.

But then again, perhaps not.

Anyway, I would definitely not recommend it.

Edit: Everybody is always complaining that IE is not adhering to the standards, let´s not start doing that as developers too.

jeroen
A: 

HTML5 introduces the "scoped" attribute on the style element, which partly addresses your use-case, because it is a very common case for mash-ups. However, as far as I know, there is no equivalent for the link element. In addition, I don't know if any browser is currently supporting the "scoped" attribute.

Alohci