11
I’m trying to get the label
simulate a fixed placeholder.
The biggest difficulty is changing the properties of label
when the input
receives the focus
, and the input
fill in the rest of the space automatically.
I tried to use the same technique float:left
with overflow:hidden
, but it didn’t work.
You could do this using only CSS?
HTML
<article>
<form>
<label>Qualquer nome para qualquer tamanho</label>
<input>
</form>
</article>
CSS
*{
margin: 0;
padding: 0;
}
body{
font-family: arial;
}
article{
margin: 5% 0 0 4%;
width: 50%;
}
label{
float: left;
padding: 2%;
background: #ccc;
line-heigt: 0;
font-size: 1em;
border-radius-right: 3px;
}
form{
width: 100%;
}
input{
display: block;
padding: 2%;
overflow: hidden;
border: 0;
background: #ccc;
font-family: arial;
font-size: 1em;
outline: none;
}
input:focus{
background: #999;
}
The input should be in front of the label?
– Zignd
The question is not very clear to me, can you explain better? Want to have the label over (in front) the input, and disappear when the input receives Focus?
– Sergio
The label will be before the input. I want to leave the label as inside the input. Simulating a placeholder.
– ivandinizaj
I don’t understand what you mean by "before" and "as if you were inside the input". Having an element above with for example z-index above does not let you click on the element below to make Focus.
– Sergio
I’m still confused about what you want to do, try drawing in the post using Drawing box characters (link Wikipedia)
– Zignd
I changed the CSS to better understand.
– ivandinizaj
I changed the CSS and left it with a nicer style. By clicking on the input I would like to modify the label background, so it looks like the same field.
– ivandinizaj