admin管理员组

文章数量:1320591

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:

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/questions/7896536/ordering-wordpress-stylesheets

Share Improve this question edited Oct 3, 2020 at 22:29 Mr No asked Oct 3, 2020 at 20:47 Mr NoMr No 11 bronze badge 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 Commented Oct 3, 2020 at 20:54
  • CSS questions are best asked over on stackoverflow – Tom J Nowell Commented 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 Commented 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. – Tony Djukic Commented Oct 8, 2020 at 16:44
Add a comment  | 

1 Answer 1

Reset to default 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

本文标签: pluginsApply only the css in my stylecss file