It’s not a super sophisticated answer, but it’s something that can help you quite simply, without JS or regex.
I made a box, imitating it’s a textarea
and the phrase actually stays outside the textarea
. Just keep in mind that you have to make some accessibility adjustments by putting role="textbox"
in the div for it semantically becomes more coherent, the taxtarea continues being accessible by tab what is good, but I had to "transfer" the outline
of :focus
of textarea
to the div
, for this I used css :focus-within
, so when you click on textarea
inside the box, the box that will receive the outline
Remember to make everything accessible with role
and aria
in div
, and for
in label
which has the text of textarea
!
Follow the image code above
.box {
font-family: 'Courier New', Courier, monospace;
font-size: 14px;
box-sizing: border-box;
border: 1px solid #ccc;
padding: 0.2em;
width: 600px;
height: 200px;
}
.box:focus-within {
box-shadow: 0px 0px 0px 2px cornflowerblue;
}
.box label {
margin: 0;
padding: 0;
width: 100%;
}
.box textarea {
resize: none;
outline: none;
padding: 0;
margin: 0;
border: none;
width: 100%;
height: 170px;
}
<div class="box" role="textbox" aria-labelledby="listaProdutos">
<label for="lista" id="listaProdutos">Estimado Familiar, pedimos que traga para o utente o seguinte produto: </label>
<textarea name="" id="lista" ></textarea>
</div>
Why not use two fields, with one of them accessible for the user to type and join everything later when sending to the server?
– Benilson
So wouldn’t it be simpler to make a simple input text that the person just enters the product name? If the text is fixed, you can insert it when handling the form information.
– Woss
@Woss I want the text to be visible to the user. I already managed to fix the text with a div, but it doesn’t look like I want to visually, see here: example, but intended that the text stay within the lines of the sheet.
– Bruno
Face the best way to do this, or at least the easiest, and make a text area fake... the text will look like it’s inside, but it’s actually outside... It would look like this, with the text box starting from the red line down http://prntscr.com/q3ak9c
– hugocsl
@hugocsl and how can I do it
– Bruno
I’ll give you an answer
– hugocsl
@hugocsl thank you
– Bruno