【问题标题】:Does css support percent class namecss是否支持百分比类名
【发布时间】:2023-01-07 20:04:42
【问题描述】:

我有一个这个类的 div:

<div class="hero-section width-80%"> A Hero Image </div>

CSS:

<style>
.width-80%{
max-width: 80%;
}
</style>

是否允许在类值中使用百分号?如果我想使用带有“%”符号的任何百分比类,如何在 css 中使用百分号?

【问题讨论】:

标签: css


【解决方案1】:

是的,你必须在你的选择器中escape它:

.width-80% {
  max-width: 80%;
  
  color: red;
}
&lt;div class="hero-section width-80%"&gt;A Hero Image&lt;/div&gt;

【讨论】:

    【解决方案2】:

    尝试这个:

    .width-80% {
      max-width: 80%;
    }
    

    【讨论】:

    • 我从来没有见过规则类,我在任何地方都找不到任何文档——而且我的任何解析器都无法识别它……你有它的链接吗?还是您的意思是[class="width-80%"]
    猜你喜欢
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-11
    • 2020-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多