我正在使用 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/