我正在關注這篇文章
對我來說,彈出窗口中的文本是一個有多行的跨度(& ltbr & gt).
我如何使彈出窗口的寬度足以適應最長的行,并在行數更多的情況下有垂直滾動條?默認情況下,它應該能夠支持20行。
目前它是這樣顯示的:
內容是:
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>
風格:
.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>
只需將彈出模式的寬度設置為最大內容。Max-content將在不換行的情況下使用所需的空間。設置最大寬度為100vw和框大小:邊界框,以阻止整個事情溢出。
對于高度,我使用CSS自定義屬性來計算要滾動的行數,并相應地設置max-height,然后設置overflow-y:auto。
下面標記的代碼:
.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>