Как перебить !important?
Привет!
Есть html сайт и у него стиль с !important (верхний)
И моя форма (нижний стиль)
И таких сайтов несколько.
На каждый ставлю свою форму обратной связи со своими стилями и js скриптом.
Как перебить родной стиль сайта с !important, не делая поиски и редактируя его? Иначе он скрывает элементы в моей форме.
Можно js скрипт либо еще как-нибудь, качество кода не важно, его потом можно сделать при желании.
Сейчас всю работу свожу к минимализму, чтобы закинул пару файлов от свой формы обратной связи, поставил кнопку на главной странице и готово.
- Вопрос задан более трёх лет назад
- 6629 просмотров
- Вконтакте
- Вконтакте


Сделайте более приоритетный селектор, добавив в него родителя (про-родителя).
UPD:
лучше так, иначе все чекеды в документе обновятся.
- Вконтакте



задать стили непосредственно в html коде в теге style — так будет выше приоритет. С помощью скрипта прописать, чтобы в html документа создавался тег style со своими стилями. Колхоз, правда, но что поделать
Чем перебить приоритет !important?
Возникла необходимость откорректировать размещенную на сайте форму обратной связи с клиентом, загружаемую скриптом партнерки. На CSS свойства некоторых дивов в ней установлен авторский приоритет !important, который, как известно, выше аналогичного пользовательского. По этой причине изменить свойства невозможно.
Подскажите, пожалуйста, как сделать пользовательский приоритет выше авторского.
- Регистрация: 15.09.2010
- Сообщений: 436
- Репутация: 100
- Webmoney BL:
?
через айфрем грузится или как?
а так можно вложенностью перебить, типа
.post__text-html h2 <
color:#000!important;
>
.nl .post__text-html h2 <
color:#7aa1bd!important;
>
How to override !important?
I have created a custom style sheet that overrides the original CSS for my WordPress template. However, on my calendar page, the original CSS has the height of each table cell set with the !important declaration:
Is there some way I can override this?
![]()
11 Answers 11
Overriding the !important modifier
- Simply add another CSS rule with !important , and give the selector a higher specificity (adding an additional tag, id or class to the selector)
- add a CSS rule with the same selector at a later point than the existing one (in a tie, the last one defined wins).
Some examples with a higher specificity (first is highest/overrides, third is lowest):
Or add the same selector after the existing one:
Disclaimer:
It’s almost never a good idea to use !important . This is bad engineering by the creators of the WordPress template. In viral fashion, it forces users of the template to add their own !important modifiers to override it, and it limits the options for overriding it via JavaScript.
But, it’s useful to know how to override it, if you sometimes have to.
![]()
Apart from overriding a style set by the style attribute, the !important should only be used when you have selectors in your style sheet with conflicting specificity.
But even when you have conflicting specificity, it is better to create a more specific selector for the exception. In your case it’s better to have a class in your HTML which you can use to create a more specific selector which doesn’t need the !important rule.
I personally never use !important in my style sheets. Remember that the C in CSS is for cascading. Using !important will break this.