Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep a text inside a div when resizing the browser window

Tags:

html

css

So I have a simple div in which I have a p with some text. I want the text to stay inside the div, and that is going good so far, but when I resize the window of my browser horizontal, the text inside the div is flowing out of the div on the bottom.

#textbox {
  position: absolute;
  left: 180px;
  top: 420px;
  height: 250px;
  width: 20%;
  background-color: white;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}

#text {
  text-align: center;
  font-family: 'Roboto', sans-serif;
  font-style: italic;
  font-size: 20px;
  word-wrap: break-word;
}
<div id="textbox">
  <p id="text">Here is some example text that is about the same amount as I really have here, but I don't want to reveal what.</p>
</div>

According to the answers on similar questions, I have to add word-wrap: break-word; which I already have. If this helps, the text is not flowing out at left or right, it flows out at the bottom.

So my question, what do I do, to keep the text inside the div when I'm moving the browser window?

like image 932
Gyrgam Avatar asked Oct 25 '25 08:10

Gyrgam


1 Answers

Just replace height: 250px to min-height: 250px;

#textbox {
  position: absolute;
  left: 180px;
  top: 420px;
  min-height: 250px;
  width: 20%;
  background-color: white;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}

#text {
  text-align: center;
  font-family: 'Roboto', sans-serif;
  font-style: italic;
  font-size: 20px;
  word-wrap: break-word;
}
<div id="textbox">
  <p id="text">Here is some example text that is about the same amount as I really have here, but I don't want to reveal what.</p>
</div>
like image 50
Itay Gal Avatar answered Oct 28 '25 03:10

Itay Gal