我正在使用
在某些情况下,根据PHP中计算的百分比,我想让单元格具有灰色背景。
例如:50%表示单元格背景的一半将是灰色的,其余部分将保持空白| 33.33%=背景的1/3等等。
我遇到的问题是,如果我将颜色应用于
以下是代码:
我可能忽略了什么,但是 CSS 不是我的强项,希望您能给予解释或帮助。非常感谢。
foreach
向一个<table>
中添加行。在某些情况下,根据PHP中计算的百分比,我想让单元格具有灰色背景。
例如:50%表示单元格背景的一半将是灰色的,其余部分将保持空白| 33.33%=背景的1/3等等。
我遇到的问题是,如果我将颜色应用于
<td>
,则<td>
中的文本会被其他div拉伸,我也会覆盖之后的文本等等。以下是代码:
$percent = 1/3; // For example
$percent_friendly = number_format( $percent * 100, 2 ); //This will return 33.33
echo '<td>'.$percent_friendly.' %
<div style="background-color: grey"> // So I want the grey to fill 33.33% of the space
</div>
<div style="background-color: white">
</div>
</td>';
目前为止应用的样式:
table {
margin-left:auto;
margin-right:auto;
font-size:18px;
}
table, th, td {
text-align: center;
border: 1px solid black;
position:relative;
}
我可能忽略了什么,但是 CSS 不是我的强项,希望您能给予解释或帮助。非常感谢。