[英]How to keep a text inside a div when resizing the browser window
所以我有一个简单的 div,其中有一些文本的 ap。 我希望文本留在 div 内,到目前为止一切顺利,但是当我水平调整浏览器窗口的大小时,div 内的文本从底部的 div 流出。
#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>
根据类似问题的答案,我必须添加word-wrap: break-word;
我已经有了。 如果这有帮助,则文本不会从左侧或右侧流出,而是从底部流出。
所以我的问题是,当我移动浏览器窗口时,我该怎么做才能将文本保留在 div 中?
只需将height: 250px
替换为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>
您只需更改样式即可将文本保留在里面。
在线演示: https : //jsfiddle.net/y5sjdtoq/
试试这个样式代码:
#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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.