正如问题所示,我有一个带有html的index.php文件,当我尝试使用外部或内部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发现的解决方案:缺少&#34;标记在元标记的内容属性中。
答案 0 :(得分:3)
<link rel="stylesheet" type="text/css" href="style.css"></link>
只有要检查的内容是添加结束标记,并且style.css文件与index.php位于同一目录中。
编辑:
我刚注意到你在内容属性中缺少最后一组引号(“)。这可能会影响页面的其余部分吗?
答案 1 :(得分:0)
另外,请确保您的外部css文件中不包含<style></style>
标记
答案 2 :(得分:0)
做一件事。通过xampp或wampp打开css文件 打开浏览器 - &gt;搜索localhost /你的文件夹然后打开css或js文件,现在复制该地址并粘贴到href或src中。希望这会有所帮助
答案 3 :(得分:-1)
链接外部CSS时,您的路径出现了问题
是你的index.php和你的style.css在同一个文件夹中吗?
<link rel="stylesheet" type="text/css" href="style.css">
尝试将其放在名为css的单独文件夹中 然后将其链接为
<link rel="stylesheet" type="text/css" href="css/style.css">
你也可以使用firefox或firebug lite插件的firebug插件来检查错误