You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

CSS代码出现“at-rule or selector expected”报错的排查求助

CSS代码出现“at-rule or selector expected”报错的排查求助

嘿,别慌呀,新手碰到这种报错真的超常见的😉!我帮你看了下代码,问题其实很简单:你把HTML里的<style>标签也一起写到CSS代码里啦!

CSS解析器只认识自己的语法规则(比如选择器、属性声明或者@media这类规则),它完全看不懂HTML的<style></style>标签,所以才会在第一行和最后一行抛出“at-rule or selector expected”的错误——它等着看CSS规则,结果看到了陌生的HTML标签。

另外我还发现代码里有两个小细节需要调整(虽然不是这次报错的原因,但会影响样式效果):

  • margin-bottom: 5;margin-bottom: 20; 没有加单位,CSS里的长度值(除了0)都需要单位,这里应该改成5px20px,不然浏览器可能无法正确识别。

给你修正后的完整代码:

p {
  font-family: Arial;
  margin-top: 0;
  margin-bottom: 0;
}

.video-title {
  font-weight: bold;
  font-size: 18px;
  width: 280px;
  line-height: 24px;
  margin-bottom: 5px;
}

.video-stats {
  font-size: 14px;
  color: rgb(96, 96, 96);
  margin-bottom: 20px;
}

.video-author {
  font-size: 14px;
  color: rgb(96, 96, 96);
  margin-bottom: 20px;
}

.video-description {
  font-size: 14px;
  color: rgb(96, 96, 96);
  width: 280px;
  line-height: 22px;
  margin-bottom: 100px;
}

.apple-text {
  margin-bottom: 50px;
  font-size: 14px;
  background-color: rgb(227, 65, 64);
  color: white;
  text-align: center;
  padding: 20px;
}

.shop-now:hover {
  text-decoration: underline;
  cursor: pointer;
}

你把这段代码放到HTML的<style>标签内部(或者单独的CSS文件里),报错就应该消失啦!

备注:内容来源于stack exchange,提问作者Laniakea

火山引擎 最新活动