1

Possible Duplicates:
Is adding CSS rules outside the Header possible?
Declare CSS style outside the “HEAD” element of an “HTML” page ?

I'm working on a CMS which doesn't permit me to edit the CSS, nor do I have access to the head to add a link to my own CSS file.

I do however have access to certain html zones of the website and would like to declare my CSS link inline with the HTML for each element.

The reason: I'm building a "garage door" with CSS3 Transitions and therefore it's important that I can declare the ID and style in my html directly.

So how would one declare a CSS file inline with the html? Here's what I've come up with, but I'm clearly missing something.

"ul id="garagedoor": href="http://linktothefile/garagedoor.css"

I realize it's entirely counter-intuitive to declare the css inline with the html, but I see no other way of getting this to work.

Thanks guys

Community
  • 1
  • 1
Gerasimos
  • 11
  • 1

1 Answers1

3

I'm working on a CMS which doesn't permit me to edit the CSS

Then either:

  1. It is a really awful CMS and should be replaced or
  2. You don't have the authority to add CSS to the site (but someone else does and you need to talk to them)

Can one declare a css file directly in an html element?

The only place that <link> or <style> elements are allowed is the <head>, although browsers will error recover from them being elsewhere.

style attributes are allowed on most elements, but are bad practise.

"ul id="garagedoor": href="http://linktothefile/garagedoor.css"

That doesn't even resemble HTML.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I have no say in the matter for the CMS being used, so I have to work with what I have. I realize the code I provided doesn't make sense, it's a rough guideline though for what I'm trying to do. Imagine trying to do inline CSS (which is possible, but instead of declaring each value, you instead call a CSS file directly). This should definitely not be seen as the correct way to add CSS to a site, but it's simply a workaround I'm looking for for my specific situation. – Gerasimos Apr 26 '11 at 16:36
  • There is no way to load stylesheets other than `` and ` – Quentin Apr 26 '11 at 16:40
  • No issue with that David, but what about inline style tags? Can you then load the the CSS directly in the inline style tag? – Gerasimos Apr 26 '11 at 17:01
  • @David -1 That doesn't really answer the question. I've worked in exactly this situation - the CMS _was_ rubbish and _did_ need replacing, but neither were high on the agenda of the developers. However, I did have permission to adjust the design of the page, and so I used `` tags within the body. `` tags within the body work as well. It's not valid, it's not great, but it works. – Dan Blows Apr 27 '11 at 14:18
  • @Blowski — To quote my answer "although browsers will error recover from them being elsewhere." – Quentin Apr 27 '11 at 14:21
  • @David That could be written a lot more clearly. The OP clearly doesn't have a lot of experience at client-side coding. The rest of the post ignores the fact that we don't know the internal politics of the OP's office. – Dan Blows Apr 27 '11 at 14:23
  • If internal politics are the root problem, then that is the problem that needs to be addressed. Invalid hacks just ask for more problems in the future. – Quentin Apr 27 '11 at 14:49