繁体   English   中英

无法将 border-top 和 border-bottom 应用到<tr>标签

[英]Unable to apply border-top and border-bottom to the <tr> tag

我想使用 html 和 css 创建一个类似井字游戏的网格结构。 我无法将顶部和底部边框应用于第二个标签。 有人可以帮忙吗?

 td{ width: 100px; height: 100px; } .MiddleColoumn{ border-left-style: solid; border-left-color: black; border-left-size: 2px; border-right-style: solid; border-right-color: black; border-right-size: 2px; } #MiddleRow{ border-top: 2px solid black; border-color: 2px solid black; }
 <head> </head> <table> <tr> <td></td> <td class="MiddleColoumn"></td> <td></td> </tr> <tr id="MiddleRow"> <td></td> <td class="MiddleColoumn"></td> <td></td> </tr> <tr> <td></td> <td class="MiddleColoumn"></td> <td></td> </tr> </table>

AFAIK,您将无法直接向 tr 添加边框。 相反,设计 td 的样式。 通过改变你的CSS来做这样的事情。

#MiddleRow td{
    border-top: 2px solid black;
    border-color: 2px solid black;
}

像这样尝试

css

#MiddleRow .MiddleColoumn{
  border-top:2px solid black;
  border-bottom:2px solid black;
}

这看起来像是CSS Tables的完美用例,使用:

  • display: table
  • display: table-row
  • display: table-cell

工作示例:

 .table { display: table; } .row { display: table-row; } .cell { display: table-cell; width: 60px; height: 60px; } .row.middle .cell { border-top: 2px solid rgb(0, 0, 0); border-bottom: 2px solid rgb(0, 0, 0); } .cell.center { border-left: 2px solid rgb(0, 0, 0); border-right: 2px solid rgb(0, 0, 0); }
 <div class="table"> <div class="row top"> <div class="cell left"></div> <div class="cell center"></div> <div class="cell right"></div> </div> <div class="row middle"> <div class="cell left"></div> <div class="cell center"></div> <div class="cell right"></div> </div> <div class="row bottom"> <div class="cell left"></div> <div class="cell center"></div> <div class="cell right"></div> </div> </div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM