How to fit text inside div box without overflowing

I’ve been creating a display area for an out, but the text keeps on overflowing out and I can’t seem to figure out why. I’ve been researching for a long time, but nothing works. I’ve tried word-wrap: break-word;, tried manually changing the width, etc., but it does not work. What should I use to help fit it inside the box’s container?

  • Note – Total is an output value off of the user’s input
#total {
  border-radius: 5px;
  background-color: lightgrey;
  width: 300px;
  border: 15px solid green;
  padding: 50px;
  margin: 20px;
  word-wrap: break-word;
}
<p id="total" style="position: absolute; right: 400px; width:200px; height: 200px; font-size: 10px;"></p>

>Solution :

Add Overflow-y:auto;

#total {
  border-radius: 5px;
  background-color: lightgrey;
  width: 300px;
  border: 15px solid green;
  padding: 50px;
  margin: 20px;
  word-wrap: break-word;
  overflow-y:auto;

}
<p id="total" style="position: absolute; right: 400px; width:200px; height: 200px; font-size: 10px;">HEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjalHEllloo sdadsasdlkmjal</p>

Leave a Reply