[英]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.