我正在尝试使用我认为将要实现的相当简单的样式来设置表格但是已经遇到了一个小问题.
该表将在每行的左侧显示一个彩色指示器,因此我使用的是border-left:5px solID red;添加它.然而,虽然边界适用 – 其中一半在行内,一半在外面.我试过添加border-collapse:崩溃无济于事,我也使用Box-sizing:border-Box但仍然有同样的问题.
最后,我还尝试将边框添加到第一个子单元格(td),但出现了同样的问题.
我已经建立了一个正在发生的事情的例子 – 我已经放入一个超大的边框来强调这个问题:
http://www.cssdesk.com/TVa67
有没有人遇到这个或有任何解决方案?
body { background: blue;}table { border-collapse: collapse; Box-sizing: border-Box; table-layout: fixed; wIDth: 100%;}th,td { background-color: #fff; padding: 10px 15px 8px;}th { border-bottom: 1px solID blue; Font-weight: normal; text-align: left;}td { border-bottom: 1px solID gray;}tr.low { border-left: 25px solID red;}
最佳答案However,although the border applIEs – half of it is insIDe the row
and half outsIDe
此行为是预期的,并按照规范.请参阅:http://www.w3.org/TR/CSS2/tables.html#collapsing-borders,其中说:
borders are centered on the grID lines between the cells…
它还说明了带有description的图表.
Has anyone run into this before or have any solutions?
是的,它可以很容易地在这个小提琴中展示:http://jsfiddle.net/abhitalks/xs7L9wn1/1/和下面的片段:
* { Box-sizing: border-Box; }table { border-collapse: collapse; border: 1px solID gray; table-layout: fixed; wIDth: 70%; margin: 0 auto;}th,td { border: 1px solID gray; padding: 6px; text-align: center;}tbody > tr:nth-child(1) > td:first-child { border-left: 16px solID red; }tbody > tr:nth-child(2) > td:first-child { border-left: 8px solID green; }tbody > tr:nth-child(3) > td:first-child { border-left: 24px solID blue; }tbody > tr:nth-child(1) > td:last-child { border-left: 16px solID red; }tbody > tr:nth-child(2) > td:last-child { border-left: 8px solID green; }tbody > tr:nth-child(3) > td:last-child { border-left: 24px solID blue; }
解:
只需为所有行添加相同宽度的透明边框即可.这样边框宽度将是相同的,它将整齐地对齐. (更新:向第一列添加了一个白色边框,以隐藏突出显示的单元格上的悬挂边框.正如您的评论所指出的那样.)
th,td { border-left: 15px solID transparent; }tr > td:first-child,tr > th:first-child { border-left: 5px solID #fff; }tr.low > td:first-child { border-left: 5px solID red; }
示例小提琴:https://jsfiddle.net/abhitalks/s9taanz7/5/
片段:
* { Box-sizing: border-Box; }body { background-color: blue; }table { border-collapse: collapse; table-layout: fixed; wIDth: 100%;}th,td { background-color: #fff; padding: 10px 15px 8px 8px; border-left: 5px solID transparent; border-bottom: 1px solID gray; }th { border-bottom: 1px solID blue; Font-weight: normal; text-align: left;}tr > td:first-child,tr > th:first-child { border-left: 10px solID #fff; }tr.low > td:first-child { border-left: 10px solID red; }
但是,这种方法会产生隐藏边框底部的副作用,因为边框与左边重叠.
解决方案2:
你可以在左边有一个额外的单元格作为指标.然后,您可以使用colgroup来控制它.这种方法比上面更整洁,并且还要求您在CSS中仅指定一次宽度.
示例小提琴2:http://jsfiddle.net/abhitalks/z7u1nhwt/1/
摘录2:
* { Box-sizing: border-Box; }body { background-color: blue; }table { border-collapse: collapse; table-layout: fixed; wIDth: 100%;}th,td { background-color: #fff; padding: 10px 15px 8px 8px; border-bottom: 1px solID gray; }th { border-bottom: 1px solID blue; Font-weight: normal; text-align: left;}.col1 { wIDth: 10px; }tr.low > td:first-child { background-color: #f00;}
当然,您也可以尝试使用@misterManSam提出的伪元素的方法,具体取决于您的实施方便性. 总结
以上是内存溢出为你收集整理的html – 表行边框 – 半输入,半输出全部内容,希望文章能够帮你解决html – 表行边框 – 半输入,半输出所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
赞
(0)
打赏
微信扫一扫
支付宝扫一扫
javascript– 旋转椭圆形SVG对象
上一篇
2022-05-29
html– 可以扩展父容器大小的子元素的垂直对齐方式
下一篇
2022-05-29
评论列表(0条)