我从今天早些时候从HTML和CSS开始,刚刚了解了Div,类和ID的了解,我开始在我拥有的一个小测试项目中实现它们。
但是,当我尝试使用两个类设置字体(使用Google字体)时,我一定是错误的,因为它们在完成的版本中都看不到。
这是HTML
<!DOCTYPE html>
<html>
<head>
<title>Project</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Dosis" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Titillium+Web" rel="stylesheet">
</head>
<body>
<div class="title">
<div id="heading">
<h1> Page Title </h1>
</div>
<div id="subheading">
<h2> Page Subtitle </h2>
</div>
</div>
<div class="description">
<p> Page Description </p>
</div>
<div class="reasons">
<div id="title">
<h3> Why us? </h3>
</div>
<div id="title">
<h4> Statement </h4>
</div>
<div id="text">
<p> Proof </p>
</div>
<div id="title">
<h4> Statement </h4>
</div>
<div id="text">
<p> Proof </p>
</div>
<div id="title">
<h4> Statement </h4>
</div>
<div id="text">
<p> Proof </p>
</div>
</div>
</body>
</html>
这是CSS
.reasons{
font-family: 'Dosis', sans-serif;
}
.heading{
font-family: 'Titillium Web', sans-serif;
}
*{
text-align: center;
}
h1 {
color: #696969;
font-size:3em;
}
h2 {
color: #fffff0;
background-color: #CD5C5C;
font-size:2.5em;
margin:0;
}
h3 {
color: #fffff0;
background-color: #CD5C5C;
font-size:2em;
margin:0.2;
}
h4 {
color: #fffff0;
background-color: #CD5C5C;
font-size:1.5em;
margin:0;
}
p {
font-size:1em;
margin:0;
}
你们中的一个人可以解释一下我出错的地方吗?我知道这可能是一个非常基本的错误,但我无法弄清楚!
好吧,您似乎与ID和类混合在一起。ID应该是唯一的(您的HTML中只有一个标签使用该ID)。课程可以应用于多个方面。ID在CSS中被称为#和类,为..
将您的ID更改为课程,使我出现了字体。
.reasons{
font-family: 'Dosis', sans-serif;
}
.heading{
font-family: 'Titillium Web', sans-serif;
}
*{
text-align: center;
}
h1 {
color: #696969;
font-size:3em;
}
h2 {
color: #fffff0;
background-color: #CD5C5C;
font-size:2.5em;
margin:0;
}
h3 {
color: #fffff0;
background-color: #CD5C5C;
font-size:2em;
margin:0.2;
}
h4 {
color: #fffff0;
background-color: #CD5C5C;
font-size:1.5em;
margin:0;
}
p {
font-size:1em;
margin:0;
}
<!DOCTYPE html>
<html>
<head>
<title>Project</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Dosis" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Titillium+Web" rel="stylesheet">
</head>
<body>
<div class="title">
<div class="heading">
<h1> Page Title </h1>
</div>
<div class="subheading">
<h2> Page Subtitle </h2>
</div>
</div>
<div class="description">
<p> Page Description </p>
</div>
<div class="reasons">
<div class="title">
<h3> Why us? </h3>
</div>
<div class="title">
<h4> Statement </h4>
</div>
<div class="text">
<p> Proof </p>
</div>
<div class="title">
<h4> Statement </h4>
</div>
<div class="text">
<p> Proof </p>
</div>
<div class="title">
<h4> Statement </h4>
</div>
<div class="text">
<p> Proof </p>
</div>
</div>
</body>
</html>