将td向右推,没有额外的标记 [英] push td to the right without extra markup

查看:89
本文介绍了将td向右推,没有额外的标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将第二行的td向右推?我知道我只需要添加一个空 td ,但我想生成更干净的标记。是否有任何css属性来避免这种情况?



 < style> table,th,td {border:1px solid black;}< style>< / head>< body>< table> < tr> < th> Month< / th> < th>储存< / th> < / tr> < tr> < td>一月< / td> < td> $ 100< / td> < / tr> < tr> < td> $ 100< / td> < / tr>< / table>  

解决方案

你可以使用一个伪元素,像这样,只CSS,没有改变的标记



这里发生的是,渲染它将作为匿名表单元格呈现,因此以与< td>< / td> 标记相同的方式将现有的一个推向右边。 p>

 

 < table& < tr> < th> Month< / th> < th>储存< / th> < / tr> < tr> < td>一月< / td> < td> $ 100< / td> < / tr> < tr> < td> $ 100< / td> < / tr>< / table>  


How to push the second row's td to the right? I know I can simply add one more empty td but I want to produce cleaner markup. Is there any css attribute to avoid that?

<style>
table, th, td {
    border: 1px solid black;
}
</style>
</head>
<body>

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>$100</td>
  </tr>

</table>

解决方案

You can do that with a pseudo element, like this, CSS only, no change in the markup

What happens here is that when the pseudo renders it will render as an anonymous table cell, hence push the existing one to the right in the same way the <td></td> markup would.

table, th, td {
  border: 1px solid black;
}
table tr:nth-child(3):before {
  content: '';
}

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>$100</td>
  </tr>
</table>

这篇关于将td向右推,没有额外的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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