html行“.{”在打开html文件时在Eclipse中被标记为错误

html line ". {" is marked as an error in Eclipse when the html file is opened

我已经使用 jdk1.8 和 Tomcat 9 将我的 Eclipse 更新到 2021-03。现在,当我打开 html 时,以下 css 在“。{ " - 预期的标识符。当我关闭文件时,错误标记消失。

 body {
        padding-top: 40px;
        padding-bottom: 40px;
        background-color: #f5f5f5;
      }
      . {
        max-width: 370px;
        padding: 1px 1px 1px;
        background-color: #fff;
        border: 1px solid #e5e5e5;
        -webkit-border-radius: 5px;
           -moz-border-radius: 5px;
                border-radius: 5px;
        -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
           -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
                box-shadow: 0 1px 2px rgba(0,0,0,.05);
      }

它期待 classname. 之后 如果您的目的是将 css 应用于整个文档,则使用

*{
        max-width: 370px;
        padding: 1px 1px 1px;
        background-color: #fff;
        border: 1px solid #e5e5e5;
        -webkit-border-radius: 5px;
           -moz-border-radius: 5px;
                border-radius: 5px;
        -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
           -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
                box-shadow: 0 1px 2px rgba(0,0,0,.05);
      }

. 用于 CSS 中的 类,因此它期望 . 后跟一个类名。 欲了解更多信息,请访问 MDN for more info

为了您的方便,下面是来自vscode的实时日志的屏幕截图

正如你所看到的那样,它表示需要标识符,这意味着在 . 选择器之后以及当你执行类似的操作时,类名是必须的 .class_name{} 你会看到错误消失了