我想根據數字增加線條的寬度(0 - 10)。線的寬度不應該更大50 %,因為我設定了left: 50%或者right: 50%線,讓它根據第二個引數向右或向左移動:
#line {
height: 10px;
background: gray;
position: relative;
}
#line::after {
content: '';
height: 10px;
display: block;
position: absolute;
width: 25%;
background: red;
right: 50%;
}
<div id="line"></div>
在我的示例中,我將 設定width為25 %在左側中心產生一條活動線。
相反,我想calc()在 PHP 中使用 CSS 來計算給定變數的寬度:
width: calc(50% / <?= $number ?>);
該數字可以保存值(步進為 1),直到10該值應導致(50 % = 100 %)左側部分、5一半等的整行。0表示沒有寬度。
我不確定這是否可行?我試過把它們分開,這似乎是正確的方向,但不是全部。
uj5u.com熱心網友回復:
calc(5% * number);應該做的作業:
#line {
height: 10px;
background: gray;
position: relative;
}
#line::after {
content: '';
height: 10px;
display: block;
position: absolute;
width: calc(5% * <?= $number ?>);
background: red;
right: 50%;
}
<div id="line"></div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/525143.html
標籤:htmlcss
上一篇:僅在反應時切換一個li元素
