ID工作时CSS类不可格式化



我正在学习HTML和CSS,尽管我观看了培训,但我发现了一件奇怪的事情,并一步一步地复制了这件事(使用Visual Studio代码(。当我向HTML文件的任何部分添加class时,我无法将任何样式应用于它。但是,如果我添加ID,样式就会应用。

我的设置:

Visual Studio代码单独的CSS和HTML文件。

不工作代码示例:

<div Class="Author">
<h1> About the Author</h1>
<img src="image link here">
</div>

然而,如果我把上面的代码改成这个:

<div ID="Author">
<h1> About the Author</h1>
<img src="image link here">
</div>

这确实有效。

是的,我确实正确地将CSS文件更改为""或"#"这里有我想念的东西吗?

我认为这不起作用:

<div Class="Author"> 

它应该是小写的:

<div class="Author"> 

然后在css引用中,它像一样

.Author {color: red}

此功能正常。你没有给我们css来工作,所以这是我能提供的最好的。

#Author {
color: red;
}
.Author {
color: blue;
}
<!-- no css applied -->
<div ID="no_css">
<h1> About the Author</h1>
<img src="image link here">
</div>
<!-- css applied to `ID` using `#` -->
<div ID="Author">
<h1> About the Author</h1>
<img src="image link here">
</div>
<!-- css applied to `Class` using `.` -->
<div Class="Author">
<h1> About the Author</h1>
<img src="image link here">
</div>

最新更新