身体{background-color}无法在外部css中工作?

Amr*_*ngh 0 html css stylesheet background-color

我无法使用外部样式表更改背景颜色.当我尝试使用内部样式表时,它的工作完美.这是代码.

ext1.css
<style>
body{
   background-color: red;
}
ul{
   color:green;
}
:link{
    color:aquamarine;
}
p{
   font-family:"arial";
    font-size:20px;
}
</style>


HTML DOC

<!doctype html>
<html>
<head>
<title> Defining external style sheet</title>
<link href="ext1.css" rel="stylesheet" type="text/css">
</head>
<body>
<ul>
<li> <a href="#Home">Home</a></li>
<li> <a href="#News">News</a></li>
<li> <a href="#Contact us">Contact</a></li> 
<li> <a href="#About">About</a></li>
</ul>
<p> NOTE: We use href="#" for test links , in real web sites we will use URL's </p>
Run Code Online (Sandbox Code Playgroud)

Pav*_*lin 10

您不能<style>在外部CSS中使用HTML 标记.

您的CSS文件应如下所示:

body {
   background-color: red;
}
ul {
   color: green;
}
:link {
   color: aquamarine;
}
p {
   font-family: "arial";
   font-size: 20px;
}
Run Code Online (Sandbox Code Playgroud)

  • 在他的例子中 - 缺少`body`和`html`的结束标签,但这不是问题(但应该修复).如果我创建一个带有html和外部css的文件而没有周围的`<style>`它可以工作.在ext1.css上包含`<style>`它不起作用. (2认同)