dongwei1855
dongwei1855
2016-03-17 14:45
浏览 686
已采纳

你如何使用CSS在PHP中设置HTML样式?

I need to be able to style some simple HTML I've written in PHP

PHP:

if ($result-> num_rows> 0) {
  readfile("ViewReturn.html");
  while($row = $result-> fetch_assoc()) {
    echo "Bird Name: ".$row["pageLink"]. "<br><br>";
  }
} else {
  echo "0 results";
}

I would like to be able to style the HTML I'm outputting at "birdname" and "page link" because it doesn't sit very well on the page. Does anyone know how to go about doing this?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • doune1000
    doune1000 2016-03-17 14:51
    已采纳

    You could add the bird name in a <span> with a class and style the class using CSS.

    Do it as below

     echo "<span class='birdname'>Bird Name: ".$row["pageLink"]. "</span><br><br>";
    

    ie, replace your code as

    if ($result-> num_rows> 0) {
      readfile("ViewReturn.html");
      while($row = $result-> fetch_assoc()) {
        echo "<span class='birdname'>Bird Name: ".$row["pageLink"]. "</span><br><br>";
      }
    } else {
      echo "0 results";
    }
    

    and in CSS, add

    .birdname{
       color:red;
    }
    
    点赞 评论
  • duanpa1898
    duanpa1898 2016-03-17 14:49

    You can add to your echo command the html elements just as you were writing directly on HTML file. For example:

    echo "<div class='some-class'>"
    while($row = $result-> fetch_assoc()) {
    echo "<someTag class='other-class' >". "Bird Name: ".$row["pageLink"]. "<br><br>" . "</someTag>";
    }
    echo "</div>"
    
    点赞 评论
  • doukong9316
    doukong9316 2016-03-17 14:53

    You can style your result by adding these elements Like

     echo "<p class='birdy'>Bird Name: " . $row["pageLink"] . "</p >";
    

    then in your CSS file or inline or in STYLE

    .birdy{
       color:blue;
       text-decoration: none;
    }
    
    点赞 评论
  • dsf11t5u1651
    dsf11t5u1651 2016-03-17 14:55
    <?php
         if ($result-> num_rows> 0) {
            readfile("ViewReturn.html");
            while($row = $result-> fetch_assoc()) {
    ?>
            <span class="birdname">Bird Name: <?php echo $row['pageLink']; ?> </span>
            <br><br>
    <?php
            }
          } else {
             echo "0 results";
         }  
    ?>
    
    点赞 评论

相关推荐