So I have a simple div in which I have ap 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?
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>
you can keep text inside by simply change you style.
online demo: https://jsfiddle.net/y5sjdtoq/
try this style code:
#textbox {
left: 180px;
top: 420px;
height: auto;
padding: 20px;
display: inline-block;
width: 240px;
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.