How to add a CSS stylesheet outside of the header?
-
How do you add several additional CSS styles to a web page, when you don't have access to the header or the linked styles sheets? Yes, you can repeatedly declare an inline style for each piece of text, but that defeats the purpose of style sheets. A fuller picture of what is desire, along with backstory is below the fold. There's a content management system that I have to work with. It writes out A) the header, B) leaves room for the user to add HTML or inline CSS, then writes out C) a sidebar and footer. In that B space, I need to make a list of information that covers every week of a year. CSS would be the best way to do this, but I don't have access to the header or the original style sheets and I'm not going to get them (seriously, not gonna happen). Inline styles could do the job, but being able to link or embed new CSS styles would be the best way, if possible. Is there a way to add a link to or embed another CSS style sheet outside of the header of a webpage?
-
Answer:
<style>@import url(/styles/mystylesheet.css);</style>
Brandon Blatcher at Ask.Metafilter.Com Visit the source
Other answers
I've included 'style' tags with CSS rules in the body before and it has worked for my use cases. The tags are supposed to go in the head, so I'm not sure how well it's supported / when it will work, but you could at least try it and see.
losvedir
Can you execute javascript code? Here's a quick-and-dirty way to insert a CSS tag:var a=document.createElement("link"); var b=document.getElementsByTagName('link')[0]; a.href='{YOUR_CSS_URL}'; a.type='text/css'; a.rel='stylesheet'; b.parentNode.insertBefore(a,b); (not tested, but should work)
mkultra
You can add style whenever you want. The big issue is that the browser may render things with the style as it is before the new one changes it. It's why you see stuff move itself around or change appearance mid-load on some poorly designed pages. Inline is kinda stinky but it has the great advantage of not showing that sort of behavior. You may want to split the difference and do an inline define block at the top of your B space simply using the STYLE tags. You can use classes and ids there so you're not re-doing things over and over but not add the additional http connection that an additional file adds.
phearlez
@import url(/styles/mystylesheet.css); This is working like a champ, thanks!
Brandon Blatcher
Two things: 1. not all browsers support @import well. A quick search will get you a compliance list. 2. you'll find that some browsers require the URL to be quoted: @import url("/foo.css");
introp
Related Q & A:
- How to add a column header to the dynamic table?Best solution by stackoverflow.com
- How to add a contact to a specific list?Best solution by Stack Overflow
- How to add a new table to a data source?Best solution by technet.microsoft.com
- How to add a button in a Fragment?Best solution by Stack Overflow
- how to add a form with a unique id on jquery?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.