代码之家  ›  专栏  ›  技术社区  ›  user3437460

使用CSS在多个表上设置字体财产

  •  -2
  • user3437460  · 技术社区  · 10 年前

    在HTML中,如果我们想使用CSS来设置所有表中字体的字体财产,我们可以使用如下内容:

    <style>
    table {
        width: 10%;
        border: 0;
        font-size:1;
    }
    </style>
    

    我的问题是:如果我想为不同的表设置不同的字体,该怎么办?例如,我有3种类型的表。其中一些,我希望字体大小为8,一些表格大小为6……等等。

    这边 不会 工作(这只是我想做的一个例子):

    <style>
    table1 {
        width: 10%;
        border: 0;
        font-size:6;
    }
    table2 {
        width: 2%;
        border: 1;
        font-size:8;
    }
    table3 {
        border: 2;
        font-size:2;
    }
    </style>
    

    希望你理解我要做的事情。我只需要几个不同的CSS表定义。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Chris    10 年前

    您需要将它们设置为类或ID。
    CSS:

    .table1 {
        width: 10%;
        border: 0;
        font-size:6;
    }
    .table2 { 
        width: 2%;
        border: 1;
        font-size:8;
    }
    #table3 {
        border: 2;
        font-size:2;
    }
    

    HTML格式:

    <table class="table1"></table>
    
    <table class="table2"></table>
    
    <table id="table3"></table>