I want to set the placeholder value of an input box using only css and not JavaScript or jQuery. How can I do this?
I recently had to do this with google's search box, this is an extreme hack reserved for extreme situations (the resulting selector was slightly different, but I made it work in this example)
/*
this is just used to calculate the resulting svg data url and need not be included in the final page
*/
var text = placeholder.outerHTML;
var url = "data:image/svg+xml;,"+text.replace(/id="placeholder"/g," ").replace(/\n|([ ] )/g,"");//.replace(/" /g,"\"");
img.src = url;
result.value = url;
overlay.style.backgroundImage = "url('"+url+"')";
svg,img{
border: 3px dashed black;
}
textarea{
width:50%;
height:300px;
vertical-align: top;
}
.wrapper{
position: relative;
display: inline-block;
}
#overlay{
position:absolute;
left:0;
top:0;
right:0;
bottom:0;
pointer-events: none;
background-repeat: no-repeat;
background-position: center left;
}
#my_input:focus + #overlay{
display: none;
}
As SVG
As IMG
As Data URI
As "Placeholder"