我需要改变细胞的背景颜色与冻结温度(32F,0C)为#bff9ff,但有一些困难。我试图在<td>中打印CSS类,但似乎它在循环中不能正常工作,并且同时被打印。
然而,这是一半的问题。我如何识别那些冻结温度和以下的细胞不是手动而是使用PHP?
<html>
<head>
<meta charset="UTF-8">
<title>Unit 3 part 2</title>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
tr:hover {
background-color:#bff9ff;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;``
}
.cell {
background-color: #00bfff;
}
</style>
</head>
<body>
<table border="1" cellpadding="3">
<thead>
<th>Fahrenheit</th>
<th>Celsius</th>
</thead>
<?php
$fahrenheit = 50;
while ($fahrenheit >= -50) {
$celsius = ($fahrenheit - 32) * 5 / 9;
print "<tr><td>$fahrenheit</td><td>$celsius</td></tr>";
$fahrenheit -= 5;
$celsius -= 5;
} ?>
</table>
</body>
</html>发布于 2017-11-17 23:21:24
通过添加一个if语句来测试温度,然后将一个类添加到td标记中,这样就可以处理它了。
<html>
<head>
<meta charset="UTF-8">
<title>Unit 3 part 2</title>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
tr:hover {
background-color:#bff9ff;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;``
}
.cell {
background-color: #00bfff;
}
.cell.freezing {
background-color: #bff9ff;
}
</style>
</head>
<body>
<table border="1" cellpadding="3">
<thead>
<th>Fahrenheit</th>
<th>Celsius</th>
</thead>
<?php
$fahrenheit = 50;
while ($fahrenheit >= -50) {
$celsius = ($fahrenheit - 32) * 5 / 9;
$class = '';
if($fahrenheit <= 32) {
$class = ' freezing';
}
print "<tr><td class='cell $class'>$fahrenheit</td><td class='cell $class'>$celsius</td></tr>";
$fahrenheit -= 5;
$celsius -= 5;
} ?>
</table>
</body>
</html>发布于 2017-11-17 23:23:54
创建一个名为“冻结”的CSS类。使用if添加冻结类,例如,
"<td class='$freezing'></td>"基本评估如下:
if (32 <= $farenheit || 0 <= $celcius) {
$freezing = "freezing";
}编辑: CSS
.freezing {
background-color: #bff9ff;
}https://stackoverflow.com/questions/47360649
复制相似问题