您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何使用外部CSS覆盖内联样式?

如何使用外部CSS覆盖内联样式?

覆盖内联样式的唯一方法是使用!importantCSS规则旁边的关键字。以下是一个示例。

div {

        color: blue !important;

       /* Adding !important will give this rule more precedence over inline style */

    }


<div style="font-size: 18px; color: red;">

    Hello, World. How can I change this to blue?

</div>

重要笔记:

。因此,您应避免同时使用!important内联样式。

!important关键字添加到任何CSS规则后,该规则就可以 于该元素的 。

它甚至会覆盖 标记中的内联样式。

CSS 2022/1/1 18:21:17 有420人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶