zoukankan      html  css  js  c++  java
  • 关于cellspacing和cellpadding

    表格的 cellspacing 和 cellpadding 我们经常会用如下的方式来清除默认样式:

    <table cellspacing="0" cellpadding="0"></table>

    很多朋友会说表现在结构中,这样不符合标准,那如何将这个表现拿出来,有些朋友或许很迷惑。我们可以用 table 的 border-collapse: collapse; 属性 来代替cellspacing=”0″,用 th,td 的 padding: 0; 属性来代替 cellpadding=”0″。

    table {
            border
    -collapse:collapse;
            border
    -spacing:0;
    }
    th
    ,td {
            padding
    : 0;
    }

    还可以用 expression 来实现 cellpadding=”0″ 的样式:

    table {
            border
    -collapse:collapse;
            border
    -spacing:0;
            padd
    :expression(this.cellPadding=0);
    }

    下面我们看下《HTML与CSS入门经典(第7版)》一书中对这两个属性的描述:

    对表格的设置不仅可以使用style属性。例如,可用 cellpadding 和 cellspacing 属性来控制表格边框的间距。cellspacing 属性设置表格边框之间和表格单元格之间的间距(以像素为单位);cellpadding 属性设置单元格中的信息四周的间距(也是以像素为单位)。如果将 cellpadding 属性设置为 0,将使表格中的所有信息尽量接近表格边框,甚至接触到边框。cellpadding 和 cellspacing 属性让你能够全面控制表格的外观。

    注意:虽然在 XHTML 中仍允许使用 cellpadding 和 cellspacing 属性,但 CSS 中存在与这两个属性等价的样式属性 padding 和 border-spacing。然而,当前的网页浏览器对这些样式属性的支持不一致,因此建议现在仍使用属性 cellpadding 和 cellspacing 来调整表格的间距。

    而《精通 CSS》一书中,作者提倡的方法是:

    table {
            border
    -collapse: collapse;
    }
    <table cellpadding="0"></table>

    至于到底用哪种方法好,朋友们自己斟酌考虑决定。

  • 相关阅读:
    Yield Usage Understanding
    Deadclock on calling async methond
    How to generate file name according to datetime in bat command
    Run Unit API Testing Which Was Distributed To Multiple Test Agents
    druid的关键参数+数据库连接池运行原理
    修改idea打开新窗口的默认配置
    spring boot -thymeleaf-url
    @pathvariable和@RequestParam的区别
    spring boot -thymeleaf-域对象操作
    spring boot -thymeleaf-遍历list和map
  • 原文地址:https://www.cnblogs.com/c9log/p/1634588.html
Copyright © 2011-2022 走看看