简体   繁体   English

禁用/覆盖Joomla模板CSS

[英]Disable / overriding Joomla template CSS

I am building a module in Bootstrap for Joomla. 我正在Bootstrap中为Joomla构建模块。 It has its own stylesheet, but the activated template (where I test it in) also uses Bootstrap and classes which adds some CSS to my module (tables, buttons, etc.). 它有自己的样式表,但是激活的模板(在其中进行测试的模板)也使用Bootstrap和类,这些类将一些CSS添加到我的模块(表,按钮等)中。

I want my module to look the same in all different templates of Joomla. 我希望我的模块在Joomla的所有不同模板中看起来都一样。 Is there a way of disabling the CSS of the template for my module so it just looks same on every template? 有没有一种方法可以为我的模块禁用模板的CSS,以便在每个模板上看起来都一样? Or do I have to declare every single line in CSS (with !important, because I think that's a lot of work?) 还是我必须在CSS中声明每一行(使用!important,因为我认为这需要很多工作?)

The CSS is rendered within an HTML document, so you can't just "disable" it on a piece of the page (which is your module). CSS是在HTML文档中呈现的,因此您不能只是在页面的一部分(即您的模块)上“禁用”它。

One possible approach is to render your module inside an <iframe> so it would be a separate document into the main HTML document. 一种可能的方法是将模块呈现在<iframe>内部,以便将其作为单独的文档添加到主HTML文档中。 But I'm not sure if this would be good/recommended, so I would rather rewrite my CSS rules so they all are inherited from my module. 但是我不确定这是否会是好的/推荐的,所以我宁愿重写我的CSS规则,以便它们都从我的模块继承。

For example: if your module is the "Fancy Contact Module", you can use an wrapper div like <div class="fancy-contact-module"> and write all your CSS rules like: 例如:如果你的模块是“花式联系模块”,您可以使用一个包装div<div class="fancy-contact-module">写像所有的CSS规则:

.fancy-contact-module p {
    color: green;
}
.fancy-contact-module a {
    text-decoration: none;
}

and so on. 等等。

You can also use your wrapper div to apply Reset CSS or Normalize CSS (or any other similar tool), so you won't need to override all CSS rules manually. 您还可以使用包装div来应用Reset CSS或Normalize CSS(或任何其他类似的工具),因此您无需手动覆盖所有CSS规则。 You can see more about Reset and Normalize here: What is the difference between Normalize.css and Reset CSS? 您可以在此处查看有关Reset和Normalize的更多信息: Normalize.css和Reset CSS有什么区别?

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

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