将border-bottom添加到表行<tr>

本文翻译自:Add border-bottom to table row

I have a table of 3 by 3. I need a way to add a border for the bottom of every row tr and give it a specific color. 我有一个3乘3的表。我需要一种方法为每行tr的底部添加一个边框并给它一个特定的颜色。

First I tried the direct way, ie: 首先我尝试了直接的方式,即:

<tr style="border-bottom:1pt solid black;">

But that didn't work. 但那没用。 So I added CSS like this: 所以我添加了这样的CSS:

tr {
border-bottom: 1pt solid black;
}

That still didn't work. 那还是行不通的。

I would prefer to use CSS because then I don't need to add a style attribute to every row. 我更喜欢使用CSS,因为我不需要为每一行添加一个style属性。 I haven't added a border attribute to the <table> . 我没有在<table>添加border属性。 I hope that that is not affecting my CSS. 我希望这不会影响我的CSS。

#1楼

参考:

#2楼

Add to your table rule: 添加到您的表规则:

table { 
    border-collapse: collapse; 
}

#3楼

Use 使用

border-collapse:collapse as Nathan wrote and you need to set border-collapse:collapse纳丹写道border-collapse:collapse ,你需要设置

td { border-bottom: 1px solid #000; }

#4楼

I had a problem like this before. 我以前遇到过这样的问题。 I don't think tr can take a border styling directly. 我不认为tr可以直接采用边框样式。 My workaround was to style the td s in the row: 我的解决方法是在样式td行中的S:

<tr class="border_bottom">

CSS: CSS:

tr.border_bottom td {
  border-bottom:1pt solid black;
}

#5楼

Display the row as a block. 将行显示为块。

tr {
    display: block;
    border-bottom: 1px solid #000;
}

and to display alternate colors simply: 并简单地显示替代颜色:

tr.oddrow {
    display: block;
    border-bottom: 1px solid #F00;
}

#6楼

I found when using this method that the space between the td elements caused a gap to form in the border, but have no fear... 我发现在使用这种方法时,td元素之间的空间会在边框中形成间隙,但不必担心......

One way around this: 解决这个问题的方法:

<tr>
    <td>
        Example of normal table data
    </td>

    <td class="end" colspan="/* total number of columns in entire table*/">
        /* insert nothing in here */ 
    </td>
</tr>

With the CSS: 使用CSS:

td.end{
    border:2px solid black;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HTML 代码是一个静态网页,如果您需要实现数据更新,需要使用后端技术。一种常见的方式是使用 JavaScript 和 AJAX 技术,通过向后端发送请求获取数据,并将数据动态更新到页面上。 具体实现步骤如下: 1. 在后端编写一个 API,用于获取设备运行状态的数据。可以使用 Flask、Django 等框架来实现该 API。 2. 在前端使用 JavaScript 和 AJAX 技术,向后端发送请求获取数据。可以使用 jQuery 或原生的 XMLHttpRequest 对象来实现。 3. 在获取到数据后,使用 JavaScript 动态更新页面上对应的元素。可以使用 jQuery 或原生的 DOM 操作方法来实现。 下面是一个简单的示例代码,使用 jQuery 实现数据更新: ``` <!DOCTYPE html> <html> <head> <title>设备运行实况</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { font-family: Arial, sans-serif; background-color: #f7f7f7; } h1 { text-align: center; margin-top: 50px; } table { margin: auto; border-collapse: collapse; border: 1px solid #ddd; width: 80%; } th, td { padding: 12px; text-align: center; border-bottom: 1px solid #ddd; } th { background-color: #4CAF50; color: white; } .status-ok { color: green; font-weight: bold; } .status-warning { color: orange; font-weight: bold; } .status-error { color: red; font-weight: bold; } </style> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { // 定时更新数据 setInterval(function() { $.ajax({ url: '/api/devices', type: 'GET', dataType: 'json', success: function(data) { // 更新数据 $.each(data, function(i, item) { $('#device-' + item.id + '-status').text(item.status); $('#device-' + item.id + '-time').text(item.time); $('#device-' + item.id + '-status').removeClass().addClass('status-' + item.status.toLowerCase()); }); }, error: function(xhr, textStatus, errorThrown) { console.log('Error: ' + errorThrown); } }); }, 5000); // 每隔 5 秒更新一次数据 }); </script> </head> <body> <h1>设备运行实况</h1> <table> <tr> <th>设备名称</th> <th>运行状态</th> <th>最近更新时间</th> </tr> <tr> <td>设备 A</td> <td id="device-1-status" class="status-ok">正常运行</td> <td id="device-1-time">2021-10-01 10:30:00</td> </tr> <tr> <td>设备 B</td> <td id="device-2-status" class="status-warning">运行异常</td> <td id="device-2-time">2021-10-01 11:00:00</td> </tr> <tr> <td>设备 C</td> <td id="device-3-status" class="status-error">停机</td> <td id="device-3-time">2021-10-01 12:11:00</td> </tr> </table> </body> </html> ``` 在上面的示例代码中,我们使用了 jQuery 的 `$.ajax` 方法向后端发送 GET 请求,获取设备状态的数据。在请求成功后,我们使用 `$.each` 方法遍历数据,并更新页面上对应的元素。每隔 5 秒钟更新一次数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值