I'm having a problem getting my conditional IE8 and below stylesheet to work. I've placed the conditional statement below the regular stylesheet links but with no result.
This is my current setup:
<link rel="stylesheet" type="text/css" media="all and (max-width: 640px)" href="/css/mobile-new.css" />
<link rel="stylesheet" type="text/css" media="all and (min-width:641px) and (max-width: 768px)" href="/css/tablet.css" />
<link rel="stylesheet" type="text/css" media="all and (min-width:769px) and (max-width: 1024px)" href="/css/tablet-landscape.css" />
<link rel="stylesheet" type="text/css" media="all and (min-width:1025px)" href="style.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" type="text/css" href="style.css" />
<![endif]-->
As you can see it should use the regular 'desktop' stylesheet as media queries are not supported in IE8 and below. If I just place
<link rel="stylesheet" type="text/css" href="style.css" />
in the head it works fine and the styles are also displayed in IE8 but I really need to seperate the stylesheets for the mobile/tablet versions.
I've already tried respond.js and css3-mediaqueries.js to skip the conditional stylsheet part but with no result.
Since you are using Internet Explorer 11 trying to emulate Internet explorer 8, you will find that it does a very poor job of it.
Use a site like Browserstack and you can run it from an actual computer running IE8 and then there, you should find that your code now works as it is supporting conditional statements, unlike IE11, which has dropped conditional statements.
You could also try testing IE8 in Windows XP Mode, which is available through Windows Virtual PC.
This Virtual Machine is made by Windows, and comes with IE8, and has helped me personally for testing with IE8.
http://windows.microsoft.com/en-ca/windows7/install-and-use-windows-xp-mode-in-windows-7
Related
I've created a mobile first responsive web page. It is working lovely in all the major browsers to my liking and is looking good on mobile phones and tablets too.
Last part is I want it to look decent in IE8.
I've read here on #3 (http://www.cognifide.com/blogs/mobile/responsibly-responsive-mobile-first-responsive-design-part-2/) you can simply serve a specific style sheet for IE9 and lower with the desktop version styles using conditional comments.
I created ie.css with my desktop styles and have added this conditional commenting to the head section however no luck, I still get the mobile styles in IE8 and lower.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="favicon.ico">
<title>Page Title</title>
<link rel="stylesheet" href="style.css" media="all">
<!--[if (lt IE 9)&(!IEMobile)]>
<link rel="stylesheet" href="ie.css" media="all">
<![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
Any ideas on whats going wrong? I've double checked that my ie.css file is sitting there in the directory right next to my index.html just like style.css. Is there some other reason this would not work?
Thanks,
if i read that correctly, you just want to target ie8?
first off, place html5shiv above all of your style sheets...unless you have style sheets that literally have no styles for ie. html5shiv needs be rendered first so it can tell ie those are elements and it needs to style them accordingly.
i'm still confused about what you want exactly, and not sure if you are targeting less than ie8, so lets just fix ie8 issue(s):
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="style.css" media="all">
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="ie8.css" />
<![endif]-->
EDIT
<!--[if lt IE 8]>
<link rel="stylesheet" href="ie.css" media="all">
<![endif]-->
<![if !IEMobile]>
<link rel="stylesheet" href="ie.css" media="all">
<![endif]>
all we've done is move html5shim above all of the style sheets. then comes the style sheet for every other browser. then comes a style sheet only for ie8. then comes the style sheet for less than ie 8 and not ie mobile.
take note: i changed the version from less than 9 to less than 8, so there's no chance of cross-referencing each other, cancelling/adding styles to each other.
again, i'm not clear thats what you wanted, but this fixes the issues i see. lmk if i misunderstood something.
EDIT: looks like the mobile not (if !IEMobile) needs different syntax, so i'm assuming trying them separate will fix it. here's reference: http://blogs.msdn.com/b/iemobile/archive/2010/12/08/targeting-mobile-optimized-css-at-windows-phone-7.aspx
Use Respond.JS - a javascript polyfill to make css media queries work in IE8
You could have styles within your mobile stylesheet that aren't decalred within yout IE sheet. therefore they aren't getting overwritten. You could exclude the mobile stylesheet on non IE stylesheets.
<!--[if !(IE)]><!--> <link rel="stylesheet" href="style.css" media="all"> <!--<![endif]-->
<!--[if (lt IE 9)&(!IEMobile)]><link rel="stylesheet" href="ie.css" media="all"><![endif]-->
Hope it will help you, add some jQuery to remove your responsive stylesheet when web page load in a ie8 below versions, So add new style sheet for ie 8 and below versions
if (jQuery.browser.version >= 8.0) {
$('link[rel=stylesheet][href~="style.css"]').remove();
}
or if you need responsive for 1.e8 0r 7, make sure that you are added these meta tags and scripts below
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
The webpage at
http://144.76.221.141:8000
is showing correct CSS styling in Chrome and Safari, but refuses to show in Firefox or Chrome. I have already seen that adding a doctype is a common fix for this, however this did not help at all with my problem. Any pointers to a solution would be greatly appreciated..
The typeon your stylesheets need to be like the following:
<link type="text/css" href="/css/parent.css" rel="stylesheet">
<link type="text/css" href="/css/landing-page.css" rel="stylesheet">
<link type="text/css" href="/css/dropit.css" rel="stylesheet">
Removing the / at the begining.
Remove the slash in the type of your stylesheet declaration:
<link rel="stylesheet" href="/css/parent.css" type="/text/css" />
to
<link rel="stylesheet" href="/css/parent.css" type="text/css" />
For this declaration that links your CSS
<link href="/css/dropit.css" rel="stylesheet" type="/text/css"></link>
You need to remove the extra slash / on type="/text/css" should be
<link href="/css/dropit.css" rel="stylesheet" type="text/css"></link>
You can write IE only CSS by adding this to your style sheet.
<!--[if IE 8]>
<style>...</style>
<![endif]-->
For further reference you can visit http://www.quirksmode.org/css/condcom.html
For iPad and other devices I disabled the scrolling of background images, because of performance problems. All works fine.
How can I disable scrolling for IE10 and IE10 mobile (Tablet)?
Use conditional commenting in your HTML file.
If the browser agent is/is not equal to IE10 then include/exclude a CSS File
<head>
<![if !IE]>
<link rel="stylesheet" type="text/css" href="nonIE.css" />
<![endif]>
[if IE]>
<link rel="stylesheet" type="text/css" href="IE.css" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="shared.css" />
</head>
Then within each browser specific css file, you can enable any features as required.
Or use a "display:none;" on an css element, to completely hide it from a browser within your conditional css.
Note: Conditional comments are an IE-only feature, other browsers treat them as ordinary HTML tags.
The above snippet borrowed from here: http://codebox.org.uk/pages/articles/conditional-comments and the article goes in to much more detail than I have. It's a good little read.
Is there a way to load a different CSS file for a specific browser?
like (poor pseudo code):
if firefox
<link rel="stylesheet" type="text/css" href="includes/MyCssFirefox.css" />
if chrome
<link rel="stylesheet" type="text/css" href="includes/MyCssChrome.css" />
if Safari
<link rel="stylesheet" type="text/css" href="includes/MyCssSafari.css" />
Ideal solution you want does not exist:
Unfortunately, a cross browser solution does not exist IF you are trying to do it on the HTML itself. However, it will work for most versions of IE. Like such:
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="includes/myIEGeneralStyle.css" />
<![endif]-->
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="includes/myIE6Style.css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="includes/myIE7Style.css" />
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="includes/myIE8Style.css" />
<![endif]-->
So the best solution:
How about a Javascript solution like such: Browser Detection. Read a bit about this class to better clarify, what that file is basically doing is simply the concept like such:
var browser = navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ? 'chrome' : 'other';
Obviously, it does more than just detect type of browser. In fact, it knows the version, OS, and much more detail that you can read about in that link. But, it does go and check all the types of browsers by replacing 'chrome' with 'mozilla', 'explorer' and so on...
Then to add your css files, just follow up with conditional statements like so:
if (BrowserDetect.browser.indexOf("chrome")>-1) {
document.write('<'+'link rel="stylesheet" href="../component/chromeCSSStyles.css" />');
} else if (BrowserDetect.browser.indexOf("mozilla")>-1) {
document.write('<'+'link rel="stylesheet" href="../component/mozillaStyles.css" />');
} else if (BrowserDetect.browser.indexOf("explorer")>-1) {
document.write('<'+'link rel="stylesheet" href="../component/explorerStyles.css" />');
}
Good luck and hope this helps!
You can use conditional comments to target IE browsers. Look at this: http://css-tricks.com/how-to-create-an-ie-only-stylesheet/. To target firefox you can check this answer: https://stackoverflow.com/a/953491/1941910. But I think there's no need to target firefox, chrome or safari, they all do a good job applying CSS.
you can do this at the server end.
if(Request.UserAgent is chrome){
//here output chrome stylesheet
}
I need a concrete if statement that will work in an .aspx file (default.aspx) that I am building, the file itself serves as my homepage. I have not moved onto further pages. I currently catering for IE8 + 7, FireFox and Chrome.
I seem to be noticing issues in layouts even though in my markup I have this:
<!-- <link rel="stylesheet" type="text/css" href="css/homepageStyes.css" /> -->
<!--[if gt IE 6]>
<link rel="stylesheet" type="text/css" href="css/ie.css" />
<![endif]-->
Whenever I comment out either line of code, my layout problems go away but at the moment I reckon the mark up posted above is not concrete enough in telling a browser which style sheet it is to attach?
I need something along the lines of but in XHTML mark up ofc:
if (browser == "ie" || browser != "ie6") // not supporting ie6
{
// attach this style sheet:
// <link rel="stylesheet" type="text/css" href="css/ie.css" />
}
else
{
// attach this style sheet:
// <link rel="stylesheet" type="text/css" href="css/homepageStyes.css" />
}
I'm a C# developer so this is my first time building a website from scratch. So the C# if statement above was a good way of explaining what I need.
Use these conditional comments:
<!--[if gt IE 6]>
<link rel="stylesheet" type="text/css" href="css/ie.css" />
<![endif]-->
<!--[if !IE]><!-->
<link rel="stylesheet" type="text/css" href="css/homepageStyles.css" />
<!--><![endif]-->
The <!--[if gt IE 6]> comment ensures only IEs newer than version 6 will process and link to ie.css.
The <!--[if !IE]> tells IE to ignore what's in that conditional comment. The <!--> that directly follows is to terminate the if !IE component while maintaining a valid document. Anything past that will be read by other browsers and parsed, so homepageStyles.css will be linked to.
The second <!--> opens a comment so that IE can safely read the <![endif]--> that directly follows.