php - 静态页面有效,但是当放入 PHP 时,CSS 无法正确呈现

标签 php html css

我在 HTML 文件中有以下代码。这将创建一个样式列表。

<style>
/* LIST #8 */
#list8 {  }
#list8 ul { list-style:none; }
#list8 ul li { font-family:Georgia,serif,Times; font-size:18px; }
#list8 ul li a { display:block; width:300px; height:28px; background-color:#333; border-left:5px solid #222; border-right:5px solid #222; padding-left:10px;
  text-decoration:none; color:#bfe1f1; }
#list8 ul li a:hover {  -moz-transform:rotate(-5deg); -moz-box-shadow:10px 10px 20px #000000;
  -webkit-transform:rotate(-5deg); -webkit-box-shadow:10px 10px 20px #000000;
  transform:rotate(-5deg); box-shadow:10px 10px 20px #000000; }
</style>
<div id="list8">
   <ul>
      <li><a href="#">9th Fall 2017</a></li>
      <li><a href="#">10th Spring 2018</a></li>
   </ul>
</div>

这是 HTML 文件呈现的方式。

enter image description here

我有以下 PHP 文件。

<?php
$link = mysqli_connect("localhost", "root", "password", "Booking_Databse");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "SELECT SemesterName FROM Semester_tbl";

if ($result = mysqli_query($link, $query)) {
?>
<style>
/* LIST #8 */
#list8 {  }
#list8 ul { list-style:none; }
#list8 ul li { font-family:Georgia,serif,Times; font-size:18px; }
#list8 ul li a { display:block; width:300px; height:28px; background-color:#333; border-left:5px solid #222; border-right:5px solid #222; padding-left:10px;
  text-decoration:none; color:#bfe1f1; }
#list8 ul li a:hover {  -moz-transform:rotate(-5deg); -moz-box-shadow:10px 10px 20px #000000;
  -webkit-transform:rotate(-5deg); -webkit-box-shadow:10px 10px 20px #000000;
  transform:rotate(-5deg); box-shadow:10px 10px 20px #000000; }
</style>
<div id="list8">
   <ul>
  </ul><?php
    /* fetch associative array */
    while ($row = mysqli_fetch_row($result)) {
      echo '<li><a href="#">' . $row[0] . '</a></li>';

    }
  ?>
     </ul>
</div>
  <?php

    /* free result set */
    mysqli_free_result($result);
}

/* close connection */
mysqli_close($link);
?>

PHP 文件是这样呈现的:

enter image description here

我希望 PHP 文件像 HTML 文件一样呈现。我不知道我做错了什么。

最佳答案

您关闭了您的 <ul>在做循环之前...

参见:

<div id="list8">
   <ul>
  </ul><?php
    /* fetch associative array */
    while ($row = mysqli_fetch_row($result)) {
      echo '<li><a href="#">' . $row[0] . '</a></li>';

    }
  ?>
     </ul>
</div>

更改为:

<div id="list8">
   <ul>
    <?php
    /* fetch associative array */
    while ($row = mysqli_fetch_row($result)) {
      echo '<li><a href="#">' . $row[0] . '</a></li>';

    }
  ?>
     </ul>
</div>

关于php - 静态页面有效,但是当放入 PHP 时,CSS 无法正确呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47966099/

相关文章:

php - 通过 css 和 html 添加响应样式后,注册和登录表单停止响应

php - Laravel 5.3 在哪里保存授权数据?

javascript - HTML5 Canvas /CSS 缩放

css - 是否有 CSS 父级选择器?

php - PDO 与 mysql 用户定义变量返回 null

Javascript如何在html表单提交中使用多个函数来验证

javascript - 如何在 jquery 或 javascript 中使用 html

html - box-shadow 属性使菜单覆盖另一个 div 并且看起来很糟糕

html - XPath 数字通配符

html - 如何在页面上垂直居中和 hor an h1?