I can't get IE8 to support :before - html

No idea why :before won't work. My IE8 browser will display it correctly on this page:
http://quirksmode.org/css/selectors/beforeafter.html
but not when I do it on this page:
http://africa.ie

IE8 does support :before.
Two possibilities:
IE is rendering the page in compatibility mode or quirks mode.
Either of these modes will disable this functionality. Add a valid doctype and set X-UA-Compatible to IE=edge to deal with this.
You're using ::before rather than :before.
This is quite a subtle one. The correct syntax is with a double-colon, but at the time IE8 was released, it was a single colon; the official syntax has been changed subsequently. All modern browsers will accept either single or double colon for ::before and ::after to accommodate this historical change, but IE8 is stuck only supporting the single colon.

it works as long as you aren't in compatability mode. If you want it to support more I might recommend the following:
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->

Removing the ::before and ::after selectors seems to get it work in IE8:
p.test:before {
padding-right: 5px;
content: url(http://quirksmode.org/pix/logo_ppk.gif);
}
p.test:after {
font-style: italic;
content: " and some text after.";
}

Related

Is there a way to set any style for a specific browser in CSS?

For example, if I want to set the corner radius in Webkit, Firefox and other than I can use the following CSS:
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
But are those styles hardcoded or is merely adding a prefix address that browser?
For example, if I want to change the margin only in Firefox could I simply add the prefix like so:
-moz-margin:-4px;
margin: 1px;
NICE TO KNOW:
And if that's possible is it possible to address a specific version or platform? For example, -moz-4.3-margin:-4px; not that I'd want to, just wondering.
And does the prefix approach work cross browser? I'm wondering because Internet Explorer.
Finally, will margin:10px ever knock out -moz-margin:10px? As in, "We, Mozilla, finally support margin so we are going to ignore all old -moz-margin tags and will just use the value in the margin tag".
It's very bad habit to apply css for specific browser. But there are solutions also:
Only Moz:
#-moz-document url-prefix(){
body {
color: #000;
}
div{
margin:-4px;
}
}
chome and safari:
#media screen and (-webkit-min-device-pixel-ratio:0) {
body {
color: #90f;
}
}
Below IE9:
<!--[if IE 9]>
body {
background:red;
}
<![endif]-->
I recommend don't use this moz, and safari prefix untill and unless necessary.
For example, if I want to set the corner radius in Webkit, Firefox and other than I can use the following CSS
No, that isn't how it works.
Vendor prefixed properties are used for experimental features. Either because the specification for the property hasn't been locked down or because the browser implementor knows their are problems with the implementation.
In general, you shouldn't use them in production code because they are experimental.
Support for the vendor prefixed versions is removed as support stabilises.
Is there a way to set any style for a specific browser in CSS?
There are several methods that have been used for that effect.
Parser bugs
By exploiting bugs or unsupported features in specific CSS engines (e.g. some versions of IE will ignore a * character on the front of a property name while other browsers will (correctly) discard the entire rule).
Conditional comments
Older versions of Internet Explorer supported an extended HTML comment syntax that could be used to add <link> or <style> elements specifically for certain versions of IE.
Support for this has been dropped.
JavaScript
Classes can be added to elements (typically the body element) using JavaScript after doing browser detection in JS.
As far as I know, prefixes were added to properties when CSS3 was being implemented by different browsers, and just property wouldn't work so we'd use -prefix-property for certain properties like gradient or border-radius. Most of them work without the prefix now for most browsers, and the prefix system has been kept only for backward compatibility.
For example, if I want to change the margin only in Firefox could I simply add the prefix like so:
-moz-margin:-4px;
margin: 1px;
This won't work. You can, however use different stylesheets for different browsers (say IE) in this manner:
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="iespecific.css" />
<![endif]-->
The browser-specific prefix version thing doesn't exist.
Hope this answers your question.
As a workaround you can detect browser version in JS, and add it to class of your root element. You can detect browser through user agent , and there are multiple libraries in npm.
Using this class as a base, you can target browsers
function detectBrowser() {
if (navigator.userAgent.includes("Chrome")) {
return "chrome"
}
if (navigator.userAgent.includes("Firefox")) {
return "firefox"
}
if (navigator.userAgent.includes("Safari")) {
return "safari"
}
}
document.body.className = detectBrowser()
p {
display: none;
}
.safari .safariSpecific, .firefox .firefoxSpecific, .chrome .chromeSpecific {
display: block
}
My Browser is
<p class="chromeSpecific">Chrome</p>
<p class="firefoxSpecific">Firefox</p>
<p class="safariSpecific">Safari</p>

a tag background image not showing on ie7

I have some a tag that are assigned to class like: class='user-home' and I'm using this css to achieve background image:
.user-options .user-home{
background-image:url('../../img/user-home.png');
background-position:center;
background-size: 14px 14px;
background-repeat:no-repeat;
border: none;
}
And the problem- This is what I'm getting on chrome/mozila/ie11
This is what I'm getting on ie7
What will be the solution? Thanks.
The rule background-size is not supported on ie7. It is recommended to use small images (14X14) and not resize it with CSS rules, this way you're saving traffic and improving your page loading time.
There is a workaround (how-do-i-make-background-size-work-in-ie) but I still think it's better to just resize your image.
That's because background-size is a CSS3 property which isn't supported before IE9...
CSS background-size not working in IE7/8
Only solution i think is to edit image to 14px 14px
The browsers like IE7 do not support CSS3 properties. So you cannot use them otherwise you get these types of results.
You need to change the background-image CSS to this:
.user-options .user-home{
background-image:url('../../img/user-home.png');
background-position:center;
background-repeat:no-repeat;
border: none;
}
and now, edit the image resolutions and change its width and height to 14x14 yourself.
Or if you want to use the current CSS, please go to this website from Google:
https://code.google.com/p/ie7-js/
And from there, include the JS needed to make the IE behave like a standard browser, this is the code:
<!--[if lt IE 7]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE7.js">
</script>
<![endif]-->
This JS will enable almost many of the CSS and HTML attributes. This should be included in head element.
Are you sure it's IE7 not the compatibility view (IE6) anyway background-size wont work with IE7
A way of your question, Earlier I used to use DD_belatedPNG Javascript to fix PNG issues in IE6
you may use one of the following tools to fix all IE issues:
Normalize
ie7-js
respond.min.js
For other HTML5 fixes and Media Query I use excanvas.js and respond.js
Code could be as follows:
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->

Safari css hack working on IE8

In a html page support these browsers Mozilla Firefox14, IE8, Safari5.1.1, Chrome19.
Since to support all these browsers I have to use css hacks in order to maintain the proper alignment of the elements on page.
Below is the css:
For Mozilla Firefox and IE8:
.dis_stats
{
position:absolute;
margin-top:-30px;
margin-left:-190px;
background:#E0E0E0;
width:141px;
height:80px;
_position:relative;
_margin-top:-460px;
_margin-left:115px;
}
For Safari & Chrome:
#media screen and (-webkit-min-device-pixel-ratio:0) {
.dis_stats
{
position:absolute;
background:#E0E0E0;
margin-top:-30px;
margin-left:731px;
width:141;
height:80;
}
}
Now what is happening on Mozilla it is running perfectly. But on IE8 it is applying the properties defined for Safari & Chrome and if I remove any of the Safari & Chrome's property then it will pick the same from intended properties (i.e defined for IE8 & Mozilla).
I am not getting any clue why is this happening. Anyone please suggest what is wrong here?
I recommend trying to work out a version that complies with standards and doesn't need hacks.
But if you must hack, you can consider conditional comments specially for IE 8 with separate stylesheet that fixes its problems:
<!--[if lt IE 8]>
<style type="text/css" src="path/to/ie-only-style.css">
<![endif]-->
This doesn't really explain what's wrong with IE, but can solve some IE-specific problems without using too much time (at cost of maintainability).

IE Hack how to make IE to skip/avoid from reading a line in the style sheet

Is it possible to make Internet Explorer skip or avoid reading a line in the CSS stylesheet?
I'm mostly concerned with IE8, but interested in solutions for any version.
To prevent IE8 (and older) from reading the styles, simply use something in your selector that it doesn’t support and that all other browsers support.
For example, add :root to your selector. Here’s an example: http://jsfiddle.net/mathias/kX6tR/
.foo { background: red; }
:root .foo { background: lime; }
:root is supported in IE9 and all other browsers, therefore this is a safe CSS hack.
It is always better to avoid hacks altogether. The right thing to do in your case is re-define your CSS rule for IE in a separate stylesheet and include it after the main style file.
<link rel="stylesheet" href="nice_browsers.css" />
<!--[if IE]>
<link rel="stylesheet" href="dumb_ie.css" />
<![endif]-->
In addition normal browsers will not download the second file, so no extra HTTP request. And the main CSS file will validate (if you care about that - and you probably should)
another option:
Let IE read the line in your stylesheet, and then overwrite the line in an ie specific stylesheet loaded afterwards by using a conditional comment:
http://www.quirksmode.org/css/condcom.html
that way you get to keep your stylesheets free from selector hacks.

Evaluate a css expression only in IE<7 w/out using conditional comments?

I already know: "Don't use css expressions!" My question is not about whether I should be using an expression or if there is an alternative; my question is simply: Can I get a css expression to only be evaluated in versions of IE prior to version 7 without using conditional comments?
I occasionally use an underscore hack to hide a rule from IE7 but IE7 seems to evaluate expressions anyway. For example, _width:700px; is ignored by IE7 but _width:expression('700px'); is still evaluated.
I know that someone will try to tell me to just use a conditional comment to include the rule, but I am looking for a way to do this without placing a single style rule into a separate file.
A note for those of you who still don't want to let it go: I've chosen to use a css expression, but I didn't do so lightly. I understand the implications and I am using an expression that only evaluates once. Stop worrying about my bad decisions and just answer the question already... ;-)
I always use the star "hack" to target IE6 specifically, but it does require your browser to be in standards compliant mode (see below).
/* IE6 only */
* html .myClass {
width: 500px;
}
I like it because it doesn't rely on parsing inconsistencies in browsers and it validates according to W3C.
As for being in standards compliant mode, you should always add a valid DOCTYPE to your pages as it results in fewer CSS bugs and browser idiosyncrasies. For an explanation of quirksmode and standards compliant mode, check out this article.
You can use this example below to play around with expressions in each browser. I tested it in FF, IE6, and IE7 and it worked as expected. I only wish that SO had syntax highlighting to recognize CSS expressions and mark them as red so you can be reminded that they are evil. Might I ask why you are deciding to use CSS expressions in the first place? A lot of people try to use them to achieve min-width in IE6 but that's not the right solution. If that's the problem you're trying to solve, I've written up an answer in a separate question demonstrating a valid CSS solution for min-width in IE6.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
.ie6 {
display: none;
}
* html .ie6 {
display: expression("block");
}
* html .ie7 {
display: expression("none");
}
</style>
</head>
<body>
<div class="ie6">
This is IE6
</div>
<div class="ie7">
This is Firefox or IE7+
</div>
</body>
</html>
You don't have to use conditional comments to add a new file. You could easily add a conditional comment to add a class to the body tag, as follows:
<!--[if lte IE 7]>
<body class="ie7">
<![endif]-->
<!--[if gt IE 7]>-->
<body>
<!--<![endif]-->
Then in your CSS you can simply define a different style for IE7 on any element you like:
#content {
width:720px;
}
.ie7 #content {
width:700px;
}
You still load the same stylesheet, but you can style elements based on their browser.
You could even extend this to have differnt styles for IE6, 7 and non-IE browsers.
You can try Rafael Lima's CSS Selector. It uses Javascript, but you can do things like:
.ie6 .myClass {}
.ie7 .myClass {}
.ie .myClass{}
I used to use !important to make non-ie browsers use a different style but then IE7 started supporting it. What I have found is that IE7 will apply a style marked !ie-only (or anything not !important) and other browsers will ignore the style as they don't recognise that.
If you need three different styles this might work but not great is you want to adhere to standards though. (normally I don't try the mix of !important and !ie-only and just have !ie-only.)
#myDiv {
height: 3.0em !important; /* non-ie */
height: 2.6em !ie-only; /* ie7 */
height: 2.4em; /* ie < 7 */
}
This answer may be what you are looking for:
In-line CSS IE hack