我正在關(guān)注這篇文章
對(duì)我來(lái)說(shuō),彈出窗口中的文本是一個(gè)有多行的跨度(& ltbr & gt).
我如何使彈出窗口的寬度足以適應(yīng)最長(zhǎng)的行,并在行數(shù)更多的情況下有垂直滾動(dòng)條?默認(rèn)情況下,它應(yīng)該能夠支持20行。
目前它是這樣顯示的:
內(nèi)容是:
BLD_V179_THROTTLE_LATEST_20230513_170843<br>Profile=IPSEC, Packet=IMIX, Mbps=884.6, KPPS=313.12, % Line Rate=4.67, % QFP=40.0<br>Profile=IPSEC, Packet=IMIX, Mbps=884.13, KPPS=313.12, % Line Rate=4.67, % QFP=40.0<br>Profile=IPSEC_QOS_DPI_FNF_SNAT_ZBFW, Packet=IMIX, Mbps=884.67, KPPS=313.12, % Line Rate=4.67, % QFP=40.0<br>
風(fēng)格:
.modal-wrapper{
background: rgba(0, 0, 0, 0.508);
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
display: none;
}
.modal{
font-family: Arial, Helvetica, sans-serif;
text-align: center;
max-width: 300px;
width: 200%;
background: wheat;
padding: 20px;
margin: 35vh auto;
border-radius: 5px;
position: relative;
}
.modal a{
text-decoration: none;
background: crimson;
color: white;
padding: 5px 10px;
border-radius: 5px;
margin: 10px;
}
.modal-close{
color: red;
border: 1px solid black;
position: absolute;
top: 5px;
right: 5px;
cursor:pointer;
width: 20px;
border-radius: 5px;
}
我的彈出菜單:
<div class="modal-wrapper">
<div class="modal">
<div class="modal-close">X</div>
<div class="modal-content">
<span>Results:</span>
<br>
<p style="font-size:70%;color:blue;" align="left" id="popup_content"></p>
</div>
</div>
</div>
只需將彈出模式的寬度設(shè)置為最大內(nèi)容。Max-content將在不換行的情況下使用所需的空間。設(shè)置最大寬度為100vw和框大小:邊界框,以阻止整個(gè)事情溢出。
對(duì)于高度,我使用CSS自定義屬性來(lái)計(jì)算要滾動(dòng)的行數(shù),并相應(yīng)地設(shè)置max-height,然后設(shè)置overflow-y:auto。
下面標(biāo)記的代碼:
.modal-wrapper {
background: rgba(0, 0, 0, 0.508);
position: fixed;
inset:0;
/*top: 0;
left: 0;
height: 100%;
width: 100%;*/
/*display: none;*/
}
.modal {
font-family: Arial, Helvetica, sans-serif;
text-align: center;
box-sizing: border-box; /* added this */
max-width: 100vw; /* changed this from 300px */
width: max-content; /* changed this */
background: wheat;
padding: 20px;
margin: 35vh auto;
/*width: 200%;*/
border-radius: 5px;
position: relative;
}
.modal a {
text-decoration: none;
background: crimson;
color: white;
padding: 5px 10px;
border-radius: 5px;
margin: 10px;
}
.modal-close {
color: red;
border: 1px solid black;
position: absolute;
top: 5px;
right: 5px;
cursor: pointer;
width: 20px;
border-radius: 5px;
}
.modal-content p {
--max-lines: 5;
--font-size: 0.7rem;
--line-height: 1.2;
max-height: calc(var(--max-lines) * var(--font-size) * var(--line-height));
overflow-y:auto;
font-size: var(--font-size);
line-height: var(--line-height);
color: blue;
text-align: left;
}
<div class="modal-wrapper">
<div class="modal">
<div class="modal-close">X</div>
<div class="modal-content">
<span>Results:</span>
<br>
<p id="popup_content">
BLD_V179_THROTTLE_LATEST_20230513_170843<br>Profile=IPSEC, Packet=IMIX, Mbps=884.6, KPPS=313.12, % Line Rate=4.67, % QFP=40.0<br>Profile=IPSEC, Packet=IMIX, Mbps=884.13, KPPS=313.12, % Line Rate=4.67, % QFP=40.0<br>Profile=IPSEC_QOS_DPI_FNF_SNAT_ZBFW,
Packet=IMIX, Mbps=884.67, KPPS=313.12, % Line Rate=4.67, % QFP=40.0<br>xx</br>
xx</br>xx</br>xx</br>xx</br>
</p>
</div>
</div>
</div>