这是示例代码(HTML(:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="The_secondweb.css">
<meta charset="utf-8">
<title><!-- There will be a title --></title>
</head>
<body>
<h1 class="title">Welcome to this website</h1>
</body>
</html>
这就是我在CSS中所做的:
#title{
text-align: center;
}
问题:
当我不使用id属性时,文本不会与中心对齐,但当我没有使用id属性的时候,代码会做它应该做的事情。我是不是在使用id属性时做错了什么,或者我们不能使用任何应该在CSS中命名标签的属性将文本居中对齐?
使用类时,必须使用"quot;而"#"用于id的情况。
你也可以在html中使用内联样式,如下所示:
<html>
<head>
<link rel="stylesheet" href="The_secondweb.css">
<meta charset="utf-8">
<title><!-- There will be a title --></title>
</head>
<body>
<h1 style="text-align: center;">Welcome to this website</h1>
</body>
</html>
在CSS中使用#是id选择器
.title{
text-align: center;
}
当你的使用类别