1

I want to add some content before the first input field in the following markup using the :before. The reason of using :before is that the markup cannot be changed.

I'm trying this, but does not work:

HTML:

<p class="submit"> <input id="submit" type="submit" value="Post" name="submit"> <input id="" type="hidden" value="" name=""> </p> 

CSS:

.submit input:before{ content:"Test "; } 

This would work, but I want to place the content inside .submit:

.submit:before{ content:"Test "; } 

Demo: http://jsfiddle.net/gb2wY/

9
  • 2
    :before is supposed to be rendered as a new first child element for the element it is applied to – but input field can not have child elements. Commented Oct 14, 2013 at 9:55
  • stackoverflow.com/questions/2587669/… Commented Oct 14, 2013 at 9:59
  • Cleanest thing to do is to use a label as a wrapper: jsfiddle.net/gb2wY/2 Commented Oct 14, 2013 at 10:02
  • You can do it using jquery .before jsbin.com/iVefeso/1 Commented Oct 14, 2013 at 10:31
  • @CBroe Except for when they can oi65.tinypic.com/r253wp.jpg Commented Mar 2, 2017 at 11:08

1 Answer 1

7

I don't think you can do this as input has no content to put the pseudo-element before.

You could use the button element instead.

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

1 Comment

Except for the dateinput field, apparently (at least in Chrome). I've just run into this issue, where the date field will accept pseudo elements, but a number field won't.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.