Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

:after and :before CSS pseudo elements hack for Internet Explorer 7

I am using :after and :before CSS pseudo elements and it is working fine in Internet Explorer 8, and all modern browsers but it is not working fine in Internet Explorer 7. Are there known hacks to work around this in Internet Explorer 7?

like image 784
Soarabh Avatar asked Nov 15 '10 06:11

Soarabh


People also ask

What is :: before and :: after in CSS?

The ::before selector inserts something before the content of each selected element(s). Use the content property to specify the content to insert. Use the ::after selector to insert something after the content.

What is :: after in CSS?

::after (:after) In CSS, ::after creates a pseudo-element that is the last child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.

What are before and after pseudo elements?

CSS ::before and ::after pseudo-elements allow you to insert “content” before and after any non-replaced element (e.g. they work on a <div> but not an <input> ). This effectively allows you to show something on a web page that might not be present in the HTML content.

What is pseudo-element CSS?

A CSS pseudo-element is a keyword added to a selector that lets you style a specific part of the selected element(s). For example, ::first-line can be used to change the font of the first line of a paragraph. /* The first line of every <p> element.


2 Answers

with any pure CSS hack it's not possible.

Use IE8.js http://code.google.com/p/ie7-js/

It has support for this. http://ie7-js.googlecode.com/svn/test/index.html

test page also there

after - http://ie7-js.googlecode.com/svn/test/after.html

before - http://ie7-js.googlecode.com/svn/test/before.html

Edit after 1st comment

You can just keep this js for IE6 and 7. other browser will not read it.

<!--[if lt IE 8]> <script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE8.js"></script> <![endif]--> 

And if you are already using jQuery in your project than you can use this plugin

jQuery Pseudo Plugin

http://jquery.lukelutman.com/plugins/pseudo/

like image 140
Jitendra Vyas Avatar answered Oct 08 '22 21:10

Jitendra Vyas


I was using IE8.js (http://code.google.com/p/ie7-js/) in a project and I had to remove it because it blocked IE7 between 10/15 secs.

To mantain the content generated with :after and :before pseudo-elements, without IE8.js, I did the following:

   .tabs {      *zoom: expression(            this.runtimeStyle.zoom="1",           this.appendChild( document.createElement("small") ).className="after"          );    }     .tabs:after,    .tabs .after {      content: '';      display:block;      height:10px;      width:100%;      background:red;    } 

I prefer this way rather than with javascript, because this will keep all selectors in the same place :)

like image 23
vieron Avatar answered Oct 08 '22 21:10

vieron