覆盖现有CSS表规则的最佳方法是什么? [英] What is the best way to override an existing CSS table rule?

查看:127
本文介绍了覆盖现有CSS表规则的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用joomla的模板,其中创建者在constant.css中定义了规则

We're using a template for joomla where creators defined the rule in constant.css

table   
{
  border-collapse:collapse; 
  border:0px; 
  width:100%;
}

当我需要带有自定义参数(宽度,边框等)的自己的桌子时,一场噩梦就开始了.如果我使用一般的html参数,则它们不起作用,因为css规则更为重要(CMIIW).如果我使用style = param,我想我无法控制表格查找IE(最多7个)的方式.

When I need my own table with a custom params (width, border and so on), a nightmare begins. If I use general html params, they don't work since css rules are more important (CMIIW). If I use style= param, I suppose I can't control how the table looks for IE up to 7 inclusive.

有没有一种通用的方法可以解决此问题,或者我只需要注释规则即可(就像我已经做过的那样).

So is there a general approach to work around this or I just need to comment the rule (as I already did).

而且,如果我说joomla模板的创建者默认情况下不应将width:100%这样的通用规则定义为正确的话,这对吗?我的意思是,如果他们不想让模板用户抱怨.

And also, am I right if I say that creators of joomla templates should not define such general rules as width:100% by default? I mean if they don't want users of their template to complain.

推荐答案

方法1

在创建的所有表上放置一个类,并创建一个覆盖属性的选择器,例如table.classname.由于只应将表格用于表格数据,因此添加类名是有意义的,因为向所有表格应用其他样式(颜色,边框)会更容易.

Method 1

Put a class on all tables that you create, and create a selector like table.classname that overrides the properties. Since you should only use tables for tabular data, adding a class name makes sense because it's easier to apply additional styles (colours, borders) to all your tables.

  • 要覆盖border-collapse: collapse,请同时使用border-collapse: separateborder-spacing: 4px(或其他值).这在IE6中不起作用,在IE7中也可能不起作用.
  • 对于边框,只需添加border规则即可.如果要在单个单元格上设置边框,请定位table.classname td并在其中放置border规则.
  • 要重置宽度,请使用width: auto或放置明确的宽度.
  • To override border-collapse: collapse, use border-collapse: separate along with border-spacing: 4px (or whatever value). This doesn't work in IE6 and may not work in IE7 either.
  • For a border round the table just add a border rule. If you want borders on individual cells, target table.classname td and put the border rule there.
  • To reset the width, use width: auto or put an explicit width.

另一种方法是查找模板中使用的所有表,向它们添加类,然后更改原始规则以使用该类.然后,任何没有该类的表都将使用默认表属性.

An alternate method would be to find all the tables used in the template, add a class to them instead, and change the original rule to use that class. Then, any tables without that class will use the default table properties.

这可能很难实现,因为Joomla模板通常会覆盖模块和组件,这意味着在许多地方会有很多表.祝你好运! :p

This is probably going to be quite difficult to implement because Joomla templates often have module and component overrides, meaning there will be many tables in many places. Good luck! :p

您是正确的,在通用表元素上设置这些样式(至少,width)对于模板是个坏主意.尽管事实上他们可能正在使用表格进行布局并不是一个好兆头.

You're correct, setting those styles (well, width at least) on a generic table element is a bad idea for a template. Although the fact they're probably using tables for layout isn't a good sign anyway.

这篇关于覆盖现有CSS表规则的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆