html – 表行边框 – 半输入,半输出

前端之家收集整理的这篇文章主要介绍了html – 表行边框 – 半输入,半输出前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试使用我认为将要实现的相当简单的样式来设置表格但是已经遇到了一个小问题.

该表将在每行的左侧显示一个彩色指示器,因此我使用的是border-left:5px solid red;添加它.然而,虽然边界适用 – 其中一半在行内,一半在外面.我试过添加border-collapse:崩溃无济于事,我也使用Box-sizing:border-Box但仍然有同样的问题.

最后,我还尝试将边框添加到第一个子单元格(td),但出现了同样的问题.

我已经建立了一个正在发生的事情的例子 – 我已经放入一个超大的边框来强调这个问题:

http://www.cssdesk.com/TVa67

有没有人遇到这个或有任何解决方案?

  1. body {
  2. background: blue;
  3. }
  4. table {
  5. border-collapse: collapse;
  6. Box-sizing: border-Box;
  7. table-layout: fixed;
  8. width: 100%;
  9. }
  10. th,td {
  11. background-color: #fff;
  12. padding: 10px 15px 8px;
  13. }
  14. th {
  15. border-bottom: 1px solid blue;
  16. font-weight: normal;
  17. text-align: left;
  18. }
  19. td {
  20. border-bottom: 1px solid gray;
  21. }
  22. tr.low {
  23. border-left: 25px solid red;
  24. }
  1. 最佳答案
  2. However,although the border applies half of it is inside the row

  3. and half outside

  4. 此行为是预期的,并按照规范.请参阅:http://www.w3.org/TR/CSS2/tables.html#collapsing-borders,其中说:

  5. Borders are centered on the grid lines between the cells

  6. 它还说明了带有description的图表.

  7. Has anyone run into this before or have any solutions?

  8. 是的,它可以很容易地在这个小提琴中展示:http://jsfiddle.net/abhitalks/xs7L9wn1/1/和下面的片段:

  9. * { Box-sizing: border-Box; }
  10. table {
  11.     border-collapse: collapse;
  12.     border: 1px solid gray;
  13.     table-layout: fixed; width: 70%; 
  14.     margin: 0 auto;
  15. }
  16. th,td {
  17.     border: 1px solid gray;
  18.     padding: 6px;
  19.     text-align: center;
  20. }
  21. tbody > tr:nth-child(1) > td:first-child { border-left: 16px solid red; }
  22. tbody > tr:nth-child(2) > td:first-child { border-left: 8px solid green; }
  23. tbody > tr:nth-child(3) > td:first-child { border-left: 24px solid blue; }
  24. tbody > tr:nth-child(1) > td:last-child { border-left: 16px solid red; }
  25. tbody > tr:nth-child(2) > td:last-child { border-left: 8px solid green; }
  26. tbody > tr:nth-child(3) > td:last-child { border-left: 24px solid blue; }
  27. 解:

  28. 只需为所有行添加相同宽度的透明边框即可.这样边框宽度将是相同的,它将整齐地对齐. (更新:向第一列添加了一个白色边框,以隐藏突出显示的单元格上的悬挂边框.正如您的评论所指出的那样.)

  29. th,td { border-left: 15px solid transparent; }
  30. tr > td:first-child,tr > th:first-child { border-left: 5px solid #fff; }
  31. tr.low > td:first-child { border-left: 5px solid red; }
  32. 片段:

  33. * { Box-sizing: border-Box; }
  34. body { background-color: blue; }
  35. table {
  36.     border-collapse: collapse;
  37.     table-layout: fixed; width: 100%;
  38. }
  39. th,td {
  40.     background-color: #fff;
  41.     padding: 10px 15px 8px 8px;
  42.     border-left: 5px solid transparent;
  43.     border-bottom: 1px solid gray;  
  44. }
  45. th {
  46.     border-bottom: 1px solid blue;
  47.     font-weight: normal; text-align: left;
  48. }
  49. tr > td:first-child,tr > th:first-child { border-left: 10px solid #fff; }
  50. tr.low > td:first-child { border-left: 10px solid red; }
  51. 但是,这种方法会产生隐藏边框底部的副作用,因为边框与左边重叠.

  52. 解决方2

  53. 你可以在左边有一个额外的单元格作为指标.然后,您可以使用colgroup来控制它.这种方法比上面更整洁,并且还要求您在css中仅指定一次宽度.

  54. 摘录2

  55. * { Box-sizing: border-Box; }
  56. body { background-color: blue; }
  57. table {
  58.     border-collapse: collapse;
  59.     table-layout: fixed; width: 100%;
  60. }
  61. th,td {
  62.     background-color: #fff;
  63.     padding: 10px 15px 8px 8px;
  64.     border-bottom: 1px solid gray;  
  65. }
  66. th {
  67.     border-bottom: 1px solid blue;
  68.     font-weight: normal; text-align: left;
  69. }
  70. .col1 { width: 10px; }
  71. tr.low > td:first-child {
  72.     background-color: #f00;
  73. }
  74. 当然,您也可以尝试使用@misterManSam提出的伪元素的方法,具体取决于您的实施方便性.

  75. 猜你在找的HTML相关文章