CSS基础样式

在网页开发里,表格是展示数据的常用工具
先看 HTML 结构
示例代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS样式</title>
    <style>
    table, td, th
    {
        border:1px solid yellowgreen;
    }
    th
    {
        background-color:yellowgreen;
        color:white;
    }
    td
    {
        padding:15px;
    } 
    td
    {
        text-align:right;
    }
    table 
    {
        width:100%;
    }
    th
    {
        height:50px;
    }
    table
    {
        border-collapse:collapse;
    }
    table,th, td
    {
        border: 1px solid black;
    }
    table, th, td
    {
        border: 1px solid black;
    }
    </style>
</head>
<body>
    <table>
        <tr>
          <th>列标题a</th>
          <th>列标题b</th>
          <th>列标题c</th>
        </tr>
        <tr>
          <td>行a,列a</td>
          <td>行a,列b</td>
          <td>行a,列c</td>
        </tr>
        <tr>
          <td>行b,列a</td>
          <td>行b,列b</td>
          <td>行b,列c</td>
        </tr>
    </table>
    <table>
      <tr>
        <th>列标题a</th>
        <th>列标题b</th>
        <th>列标题c</th>
      </tr>
      <tr>
        <th>行标题a</th>
        <td>行a,列b</td>
        <td>行a,列c</td>
      </tr>
      <tr>
        <th>行标题b</th>
        <td>行b,列b</td>
        <td>行b,列c</td>
      </tr>
  </table>
</body>
</html>


两个表格承载不同数据展示需求。接着用 CSS 进行美化,设置边框时,使用yellowgreen,通过border-collapse:collapse让边框合并,避免出现难看的间隔。表头th设置了背景色yellowgreen和白色文字,height:50px让表头高度合适。单元格td设置padding:15px增加内边距,内容不拥挤,text-align:right让单元格内容右对齐,排版更规整。表格宽度设为width:100%,能适配不通设备宽度。

运行结果如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值