gpt4 book ai didi

html - 使用 Div 标签在 CSS 中组织 HTML 元素——我在为某些类实现字体时哪里出错了?

转载 作者:行者123 更新时间:2023-11-28 04:45:04 24 4
gpt4 key购买 nike

我今天早些时候开始使用 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>

关于html - 使用 Div 标签在 CSS 中组织 HTML 元素——我在为某些类实现字体时哪里出错了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41007461/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com