If you only have access to the CSS (say, because another department owns the HTML, or it's being introduced through another method), you'll have to use !important
. Use of !important
is absolutely fine, as it was intended to be a remedy to situations exactly like this. The idea of it being "bad practice" is wrong (unless you're using it to be lazy about your CSS specificity).
p:hover{border:2px solid red !important}
<body>
<p style="border:2px solid green">foobar</p>
</body>
Browsers don't have a built-in CSS declaration for p:hover
like they do for an a:hover, a:active, a:visited
, etc; thus, the inline style in the HTML is the ONLY style being recognized at run-time. Unless... there's an !important
available to give :hover
a style.