如下css代码,已经加了important,为什么还是显示白色

.chatContent{
             color:black;
             margin-top:6px;
         }
         .chatContent.hisChatContent{
             color:black !important;
             margin-top:6px;
         }
阅读 2.3k
4 个回答
.chatContent.hisChatContent

两个class名之间是不是少了个空格?important一般情况下优先级是最高的;可以检查下.hisChatContent的css是什么,再根据优先级去修改css选择器
!important > 行内样式>ID选择器 > 类选择器 > 标签 > 通配符 > 继承 > 浏览器默认属性

html 是怎么写?

假设html结构:

`<p class="chatContent">hello</p>`

.chatContent.hisChatContent {}这样写,你要class="chatContent hisChatContent"这样才生效

或者是js控制的

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题