3

I am working on an input form, with different input fields. They all get an attribute with their form.

Eg:

<input class="input-text" form="price">

or

<input class="input-text" form="percent">

I would like to add a suffix with the pseudo element ::after but cannot figure out how.

Ive already tried this CSS:

input[form="price"]::after{
    content: "&euro;";
}

and this:

input::after[form="price"]{
    content: "&euro;";
}

The problem seems to be with the ::after itself, but i cannot figure out what it is.

2
  • 2
    In addition to the answers given about generated content on input elements, there are a couple of other issues with your attempts 1) content being a CSS property does not understand HTML character entity references - you can either use the appropriate Unicode escape or the actual euro symbol 2) ::after being a pseudo-element must be placed last in the selector. Commented May 23, 2014 at 7:36
  • Agree. You have to use instead of &euro; Commented May 23, 2014 at 7:37

3 Answers 3

3

Pseudo classes like after and before cannot work on input elements. Why so? Because they work only on elements which can contain html markup. An input tag doesn't.

Robert Koritnik explained this quite good in this question.

There're other questions like that and like this:

Sign up to request clarification or add additional context in comments.

Comments

1

Clearly saying no you cannot do that in non container tags.

According to w3 standard :after or :before can be used in only container element. So you will have to use javascript.

See specification http://www.w3.org/TR/CSS2/generate.html#before-after-content

But there is an alternative you can use contenteditable property which makes div editable & then you can use after tag. But contenteditable is introduced in html5.

Here is a js fiddle http://jsfiddle.net/madterry/W4Y58/ . Down side is you cannot use this as form field & it is not widely supported.

Comments

0

The problem is, that pseude elements are only supported on container elements, but not on allready replaced elements like images or input fields.

This is because they get rendered in the element itself, which is clearly impossible on input elements.

In the W3C specification it is even defined.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.