Help - Search - Members - Calendar
Full Version: Css Changing Script Based On Your Browser
Invision Power Services > Community Forums > Community Web Design and Coding
simonguyen
Is there a way for a CSS changing script to change your coding counting on your browser?like using something that finds out what browser your using and changes the css file for your layout to use?
IAIHMB
There are a few ways that you could go about this. I would just use JavaScript and link to a different stylesheet depending on the browser used.
simonguyen
Can you show me the script since i found one http://www.sheetfeeder.co.uk/page.php?sect...id=9&page_id=23 but i could not get it to work.
_
CODE
if(navigator.userAgent.indexOf('MSIE') != -1)
{
        var style = document.getElementsByTagName('head')[0].appendChild(document.createElement('link'));
        style.rel = "stylesheet";
        style.type = "text/css";
        style.href = "msie.css";
}


Just an example of a stylesheet that would only load in MSIE. You can use document.all, etc. checks instead for wider support.
Sebastian Mares
You could also use PHP and then echo the style-sheet related line:

CODE
if(navigator.userAgent.indexOf('MSIE') != -1)
{
echo '<link href="style1.css" media="screen" rel="stylesheet" type="text/css" />';
}
else
{
echo '<link href="style2.css" media="screen" rel="stylesheet" type="text/css" />';
}
ranbo
And you can use the differences that the browsers can surport to specify the different css code.
A sample is here.
CODE
PADDING-TOP: 11px !important;    /*not IE*/
PADDING-TOP: 9px;   /*IE*/
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.