0

How can I ensure that for a given Wordpress HTML block, it uses just the css I provide in my (large) style.css file. I've placed the style.css file in a plugin, it looks good, but Wordpress insists on lengthening some of the graphics and squishing others.

Everything looks great when I view the HTML file in a browser outside of Wordpress, and I'd hate to have to stick !important on every single attribute and add probably quite a few dozen more.

It looks like the following post helped with my problem:

https://stackoverflow.com/questions/7896536/ordering-wordpress-stylesheets

4
  • 3
    This sounds like a CSS specificity issue, not necessarily a WordPress issue. wp_enqueue_style() has a $deps parameter to enqueue your css after another specific CSS file. If another file is overwriting your CSS you need to get more specific or you need to enqueue after it to ensure your CSS has priority. I'm not sure this question is going to be answerable in its current format.
    – Howdy_McGee
    Oct 3, 2020 at 20:54
  • CSS questions are best asked over on stackoverflow
    – Tom J Nowell
    Oct 3, 2020 at 21:13
  • 1
    Thanks, you're likely right. It's just that the css works fine outside of Wordpress.
    – Mr No
    Oct 3, 2020 at 21:39
  • Take a look at your source code and see which loads first, the block.css or your style.css. It looks fine outside of WordPress because the block.css isn't interfering. Oct 8, 2020 at 16:44

1 Answer 1

0

You can't, not without isolating the insides of the block. This means you would need to use an iframe or build a web component. This will require significant effort, and also carry lots of downsides and new problems.

Instead, investigate CSS specificity as fundamentally it's a CSS problem not a WordPress problem. Note that by specificity I don't mean put !important on every rule

1
  • Thank you so much. I thought this might be true. I'll give it a few more tries to isolate what I'm doing wrong. Maybe I've got a goofball setting or three somewhere.
    – Mr No
    Oct 3, 2020 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.