Javascript 取消激活";元素.风格“;在css/html中?
我在Chrome developer tools窗口的“样式”选项卡中看到此css代码:Javascript 取消激活";元素.风格“;在css/html中?,javascript,html,css,siteorigin,Javascript,Html,Css,Siteorigin,我在Chrome developer tools窗口的“样式”选项卡中看到此css代码: element.style { height: auto; width: 100%; margin-top: -148px; } 我想用.css文件中的css代码覆盖它: .so-widget-sow-simple-masonry-simple-masonry-d75171398898 .sow-masonry-grid-item img { width: auto;
element.style {
height: auto;
width: 100%;
margin-top: -148px;
}
我想用.css文件中的css代码覆盖它:
.so-widget-sow-simple-masonry-simple-masonry-d75171398898 .sow-masonry-grid-item img {
width: auto;
height: 244px;
margin-top: 0px;
margin-left: auto;
margin-right: auto;
}
但是元素.style
的样式定义已经存在。
我找不到这么快的.js。
有人能帮我吗?
Thx您可以随时使用:
.so-widget-sow-simple-masonry-simple-masonry-d75171398898 .sow-masonry-grid-item img {
width: auto !important;
height: 244px !important;
margin-top: 0px !important;
margin-left: auto;
margin-right: auto;
}
重要样式将覆盖内联样式,除非内联样式也具有!重要的子句(但这实际上很少见)。当然,可以删除元素上的
style
属性:
element.removeAttribute('style');
如果
元素.style
消失,CSS文件的规则将可见。您可以添加!每种风格的结尾都很重要
例如,请使用以下命令:
height: 244px !important;
而不是
height: 244px;
您在chrome developer窗口中看到的
元素样式
是元素上写入的内联
element.style {
/*this all are the inline written styles*/
}
现在说到这里,但是有了这个代码,element.style已经准备好了
由于CSS优先级,您无法覆盖样式。在这种情况下,规则是内联CSS比外部CSS具有更高的优先级
那么你能做什么呢
删除内联css
,无论其写入何处。这样,您的外部css将应用将样式设置为!重要信息
在外部CSS文件中。这里的人已经提到了这个解决方案,但并不总是推荐这样做- 如果您必须使用两个单独的文件来编写这两个类呢??然后是另一个CSS优先级规则
(请记住,文件加载到DOM中时没有优先级,而是关于其在DOM中的位置)最后放置在DOM中的文件将具有优先级
尝试通过添加来覆盖首选项!对价值观来说很重要。。但这是不可取的…好吧,这是可行的,但还有其他解决方案吗?您可以检查删除特定的内联样式