php - 如果使用 PHP,则 CSS 不适用

标签 php css codeigniter

我正在使用 codeigniter,for 循环中的任何数据都没有应用 CSS。该文件指向正确,因为所有其他 css 工作正常,但我无法在任何地方找到解决方案

HTML:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE = html>
<html lang="en">
<head>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url('/assets/css/home.css')?>">
     <title>Spill.It</title>

</head>
<body>
    <header>
    <div id="gifLogo">
        <img src="<?php echo base_url('/assets/images/homelogo.gif')?>" width="100%" alt="Spill.It Logo">
     </div>
     </header>
<!-- Foreach loop to print all messages from the user. -->
<?php foreach ($messages as $row): ?>
    <div id=messageDisplay>
    <?php if ($row->user_username == null){
        echo '<p>Nothing has been spilt here yet sorry!</p>';
        }?>
    <h1><?php echo $row->user_username;?> : </h1><p><?php echo $row->text;?></p>
    <p id="time"> Posted At :<?php echo $row->posted_at;?></p>

    </div>  
<?php endforeach ?>
</div>
</body>
</html>

CSS(我没有包含所有的 css,只是循环中的部分,因为我的 css 文件非常困惑):

#messageDisplay {
    text-align: center;
    padding-left: 10em;
    padding-right: 10em;
    border: 1px solid #4099ff;
    border-radius: 6px;
    box-shadow: 0 0 8px #4099ff;
    margin: 20px;
padding: 5px;   
}
#time {
    font-size: 2px;
}

最佳答案

在您的代码中,您重复了 CSS ID。 CSS ID 可以在整个页面中使用一次,因为 ID 必须是唯一的。

您应该改用类。

CSS

.messageDisplay {
    text-align: center;
    padding-left: 10em;
    padding-right: 10em;
    border: 1px solid #4099ff;
    border-radius: 6px;
    box-shadow: 0 0 8px #4099ff;
    margin: 20px;
    padding: 5px;   
 }
.time {
    font-size: 2px;
 }

PHP

 <div class="messageDisplay"> </div>

关于php - 如果使用 PHP,则 CSS 不适用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40196540/

相关文章:

php - 我们可以合并两个查询,将结果返回为行

javascript - 读取文本文件,通过 PHP 回显并每隔几秒用 JS 刷新它

html - 在一个 div 中居中放置一个表单,并在右侧显示另一个缩进的 div

html - 如何使用 css height 属性在 HTML 表格中显示滚动条

php - Codeigniter 应用程序可以在一个子域中运行,但不能在另一个子域中运行。为什么?

php - 运行 CodeIgniter 项目

php - 从 CURL JSON 响应 php 数组中获取特定值

php - preg_match - 查找数据

css - 无法剪辑图像(css)

php - Twilio 异常在 codeigniter 中给出错误