views:

401

answers:

1

Hi,

I am trying to use :after CSS pseudo element on INPUT field, but it does not work. If I use it with SPAN, it works OK.

<style type="text/css">
.mystyle:after {content:url(smiley.gif);}
.mystyle {color:red;}
</style>

This works (puts the smily after "buu!" and berfore "some more")

<span class="mystyle">buuu!</span>a some more

This does not work - it only color someValue in red, but there is no smiley.

<input class="mystyle" type="text" value="someValue">

What am I doing wrong? should I use another pseudo selector. Note: I can not add SPAN sround my INPUT; because it is being generated by a third party control.

Matraj

+1  A: 

:after and :before are not supported in internet explorer 7 and under on any elements.

It's also not meant to be used on replaced elements such as form elements (inputs) and image elements.

In other words it's impossible with pure CSS.

However if using jquery you can use

$(".mystyle").after("add your smiley here");

API docs on .after

To append your content with javascript. This will work across all browsers.

Alex
Alex, I am using IE8 and latest FF, so IE7 is not an issue. I was seraching for any documentation about limiatation of :after, but was unable to find it. http://www.w3.org/TR/CSS2/generate.html states, that it is inserted after the current node in document tree so it should work in both cases.
matra
Unless you are building the page just for your own use a large percentage of the internet use those browsers still. The w3c spec says this yes; but as you well know browsers implement their own interpretation of the spec. Using :after on an input will only work in Opera 9+, but is not implemented in IE, FF, safari or chrome because of the way they internally construct the DOM - again it can't be done with pure CSS.
Alex
Thanks for the answer (BTW: I am building intranet application which wil be used by few internal users)
matra