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

1
  • Not only is that counterintuitive, it plain doesn't make sense... Commented Apr 26, 2011 at 15:52

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

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.
There is no way to load stylesheets other than <link> and <style> (well, you can use XML PIs, but not in any practical sense in the context of HTML).
No issue with that David, but what about inline style tags? Can you then load the the CSS directly in the inline style tag?
@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 <style></style> tags within the body. <link> tags within the body work as well. It's not valid, it's not great, but it works.
@Blowski — To quote my answer "although browsers will error recover from them being elsewhere."
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.