【发布时间】:2014-07-05 01:17:31
【问题描述】:
正如问题所暗示的,我有一个 index.php 文件,其中包含 html,当我尝试使用外部或内部 css 对其进行样式设置时,它不起作用。但是内联CSS有效。顺便说一句,我在win7上使用xampp来测试网站。文件结构看起来像这样 c:/xampp/htdocs/test/index.php
相关html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width>
<!--<link rel="stylesheet" type="text/css" href="style.css">-->
<!--This css file contains the css shown below as internal css-->
<style>
body{
background-color: blue;
color: white;
}
.header{
color: white;
}
</style>
<?php
function somefuntion(){
/*I will be adding this function later once the html skeleton
is done.
This function will be calculating some numbers based on the
current date and echoing it.*/
}
?>
</head>
<body>
<section class="header">
<p>Spring</p>
</section>
<section class="body">
<p>Hello world</p>
</section>
</body>
</html>
谁能解释一下为什么内部 CSS 不起作用?
hRdCoder 找到的解决方法:元标记的内容属性中缺少 " 标记。
【问题讨论】:
-
请确保不要在标头中注释掉您的外部 CSS 文件,否则将不会应用。
-
我在使用内部和外部 css 时都有问题,所以在检查内部 css 是否有效时,我在标题中注释掉外部 css 文件,反之亦然。
-
试试
<link rel="stylesheet" type="text/css" <?php echo 'href="'.base_url().'/css/style.css"'; ?>> -
它说致命错误:调用未定义的函数 base_url()
-
很抱歉;错字。
<link rel="stylesheet" type="text/css" <?php echo 'href="/test/style.css"'; ?>>如果它位于名为test的文件夹中。如果不是并且文件在根目录下,请尝试<link rel="stylesheet" type="text/css" <?php echo 'href="/style.css"'; ?>>