I know there are lot's of questions regarding this query here but none of them provide the solution for me.
HTML
<input id="tb1" type="text" class="note" />
<br>
<p class="note1"> This is not done.</p>
CSS
p.note1:before{
content: "Note:";
}
tb1.note:before{
content: "Enter your number";
}
I am trying with above code and the variation as found on the web but none seems to work for input tag. It's working for p tag.
EDIT: I can't add value attribute to input tag and manage css for the desired result. It's the limitation of the system.
EDIT2: Forget about my css, is there any way that placeholder text is possible without using placeholder attribute and just with plain css for input type="text"
If you cant manipulate the html and use
placeholder=""
. Use javascript to manipulate the placeholder. Every css approach is hack-isch anyway. E.g. with jQuery:$('#myFieldId').attr('placeholder', 'Search for Stuff');
It doesn't work for the simple fact that this:
is not valid.
<input />
elements are not containers. As the spec notes, endtags are forbidden (and essentially ignored by the browser): http://www.w3.org/TR/html401/interact/forms.html#h-17.4Another way this can be accomplished, and have not really seen any others give it as an option, is to instead use an anchor as a container around your input and label, and handle the removal of the label via some color trickory, the #hashtag, and the css a:visited. (jsfiddle at the bottom)
Your HTML would look like this:
And your CSS, something like this:
You can see this working over at jsfiddle, note that this solution only allows the user to select the field once, before it removes the label for good. Maybe not the solution you want, but definitely an available solution out there that I have not seen others mention. If you want to experiment multiple times, just change your #hashtag to a new 'non-visited' tag.
http://jsfiddle.net/childerskc/M6R7K/
The selected element MUST be a container tag. An empty tag like
<input>
doesn't have any children element.If you can't edit your HTML code manually, you're still able to that by using JavaScript:
Update
If you want to achieve this by using CSS only, you need to have a container element wrapping your
<input>
(or come after it).BUT It doesn't work correctly as
placeholder
do. You'll not able to check the value of<input>
by CSS. If you write something inside the<input>
, afterblur
event, the generated placeholder will be displayed over the<input>
again.HTML:
CSS:
JSBin Demo
EDIT:
Try this for starters: (Note: you'll need some js to detect if text has been entered in the input)
Apart from this - I don't think this there is a css solution for placeholder text on an input element without using the placeholder attribute.
FIDDLE
Markup
css
You can't use pseudo elements on an
input
tag - or any other non-container elements for that matterFrom the Pseudo-Elements tag info:
I have found this method but not supported by all browsers:
Note: you have forgot to place an id selector
#
tb1.notesee this link