简体   繁体   English

id 属性在 vs 代码(HTML)中无法识别

[英]id attribute not recognised in vs code ( HTML)

Today I was learning HTML.今天我在学习 HTML。 it was about ids and classes.这是关于 id 和课程的。 When I typed id in vs code it was supposed to show a suggestion box .当我在 vs code 中输入 id 时,它应该显示一个建议框 I typed id = "mainBox" class ="redBg" but it did not change the color as it was shown in the video.我输入了 id = "mainBox" class ="redBg" 但它没有改变视频中显示的颜色。 ( all my other suggestions like h1 ! script are working) Can some help? (我所有其他建议,如 h1 !脚本都在工作)可以帮忙吗?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div> 
**id = "mainBox" class ="redBg"**       
</div> 
</body>
</html>

put id and class inside the opening div tag将 id 和 class 放在开始的 div 标签内

 <div id="idName" class="className">       

Check the connection between html and css file!检查html和css文件之间的连接! Yoh must have link tag in head element like this!哟必须像这样在头元素中有链接标签! --> -->

<link rel="stylesheet" href="index.css">

A div is a Content Division element , so it's essentialy a box on you page where you store some content like text and images. div 是一个Content Division 元素,因此它本质上是您页面上的一个框,您可以在其中存储一些内容,例如文本和图像。 Because you will probably use a lot of these divs when creating a page you're giving them an id, like a unique name, so you'll later know whats what.因为您在创建页面时可能会使用很多这样的 div,所以您要给它们一个 id,比如一个唯一的名称,这样您以后就会知道什么是什么。 And you'll add a class like redBG so you'll can style all elements (this one and for example all other divs) with this class in CSS to make a background-color red for example.并且您将添加一个 class 像 redBG 这样您就可以使用 CSS 中的 class 设置所有元素(这个和例如所有其他 div)的样式,以制作背景。

So rewrite that part of your code like:所以重写你的代码的那部分,比如:

<body>
   <div id="mainBox" class="redBg">       
   </div> 
</body>

The difference is the location of id and class and the whitespaces.不同之处在于 id 和 class 的位置以及空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM