简体   繁体   English

仅使用CSS和JS进行CSS悬停覆盖

[英]css hover override using only css and JS

I have a code that i can only edit the CSS and the JS. 我有一个代码,我只能编辑CSS和JS。 The problem is that the page loads a default css that cannot be altered but you can run an alternative css and JS to add content to a page and modify the css. 问题是页面加载了无法更改的默认CSS,但是您可以运行替代的CSS和JS来向页面添加内容并修改CSS。 So i guess the css that is loaded overrides the default one. 所以我想加载的CSS会覆盖默认的CSS。 But the problem is that you can't just say 但问题是你不能只说

a:hover {
background-color: red;
}

You would have to reset background color with none and add underline and stuff. 您将不得不不设置任何背景色并添加下划线和填充物。

so how can i tell my css to put my *:hover important over any else and remove the default hover? 所以我怎么能告诉我的CSS把*:hover放在其他任何地方都重要,并删除默认的hover?

The css may be too nested. CSS可能过于嵌套。 Adding an !important tag would help. 添加!important标签会有所帮助。 But it's more semantic to follow the train of elements. 但是遵循元素的训练更具语义。 Right click the element you want to style. 右键单击要设置样式的元素。 When you're looking at the editor, you'll see the specificity on the right side (where the css is) and then you can copy the selector they have. 当您查看编辑器时,您会在右侧(css所在的位置)看到特定性,然后可以复制它们具有的选择器。 Using this selector should allow you to overwrite any styles necessary. 使用此选择器应该可以覆盖所有必需的样式。

在此处输入图片说明

Far top right of the image. 图片的最右上角。 The .container is the overall class used here. .container是此处使用的整体类。 In some cases you may see something like. 在某些情况下,您可能会看到类似的内容。 (From Foundation) (来自基金会)

.top-bar-section li:not(.form) a:not(.button)

Add following in your CSS and make sure you load it after default CSS. CSS添加以下内容,并确保您在default CSS之后加载它。

a:hover {
     background-color: NONE !important;
}

Using Javascript 使用JavaScript

$('body').append('<style>a:hover { background-color: none !important; }</style>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM