When I insert my text it goes beyond my div. Please help me.
When I insert my text it goes beyond my div. Please help me.
Replace height
of div
with min-height
, thereby
height of the div
will be a minimum height, and can be expanded by the text, also add the class word-wrap: break-word;
to the tag <p>
so that the text entered in it breaks line when arriving at the width
limit of the element in which it finds, in this case, its div
.
Note:
$(document).ready(() => {
$("#input").keyup(() => {
var valInput = $('#input').val();
$("#pTexto").text(valInput);
});
});
.texto{
width:200px;
min-height: 20px;
background-color:#000;
color:#fff;
}
p{
word-wrap: break-word;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script></head><body><inputtype="text" id="input" placeholder="digite o texto aqui">
<div class="texto">
<p id="pTexto"></p>
</div>
</body>
</html>