2017-11-17 1 views
0

얼어 붙은 온도 (32F, 0C)로 배경색을 # bff9ff로 변경해야하지만 약간의 어려움이 있습니다. <td> 안에 CSS 클래스를 인쇄하려고했지만 루프 내부에서 올바르게 작동하지 않고 동시에 인쇄되는 것 같습니다.루프를 사용하는 동안 PHP를 사용하여 테이블의 셀 배경색을 변경하십시오.

그러나 문제는 거의 없습니다. 어떻게 동결 온도가 있고 수동이 아닌 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> 

답변

0

온도를 테스트하기 위해 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> 
+0

다행를, 대답을 받아주십시오. 감사! –

0

"정지"라는 CSS 클래스를 만듭니다. 예를 들어, 동결 클래스를 추가하는 경우

"<td class='$freezing'></td>" 

는 기본적으로이 평가을 사용

if (32 <= $farenheit || 0 <= $celcius) { 
    $freezing = "freezing"; 
} 

편집 : CSS는 당신을 위해 일

.freezing { 
    background-color: #bff9ff; 
} 
관련 문제