简体   繁体   English

CSS通过整个父行将内部元素边框水平延伸

[英]CSS extend a inner element border horizontal though the whole parent row

I am dynamically generating a table. 我正在动态生成一个表。 The row has many cells. 该行有很多单元格。 One cell has a ul list in it. 一个单元格中有一个ul列表。 Some other cells in the same row have the same kind of ul list with the exact same number of li element. 同一行中的其他一些单元格具有相同种类的ul列表,且li元素的数量完全相同。

So I want to strike a feeling that the li items, though they are in different cells, they are visually on the same row. 因此,我想产生一种感觉,即li项虽然位于不同的单元格中,但它们在视觉上位于同一行。 Without a border, it's hard to match them in the same row. 没有边框,很难在同一行中匹配它们。 So I want to add a border line in the ul/li but since it is in the cell, I can't make it wide across the whole table row to connect with the other list in another cell in the same row... 所以我想在ul/li添加一条边界线,但是由于它在单元格中,因此无法使其在整个表格行中都变宽,无法与同一行中另一个单元格中的其他列表进行连接...

Changing html is troublesome. 更改html很麻烦。 Any CSS way to achieve this? 有什么CSS方式可以做到这一点?

Its hard to say without seeing some code... But if I understand correctly, there is no easy way to put one line across table cells the way you are describing. 不看一些代码就很难说...但是,如果我理解正确的话,没有一种简单的方法可以按照您所描述的方式在表格单元格中放置一行。 You could however apply a bottom border to the li elements in each row like this (adds border to the third list item in each list): 但是,您可以像这样在每行中的li元素上应用底部边框(将边框添加到每个列表中的第三个列表项):

td li:nth-child(3) {
    border-bottom: 1px solid red;
}

fiddle 小提琴

Its not exactly what youre looking for but it helps identify items in a row. 它不完全是您要查找的内容,但可以帮助您连续识别项目。

After re-reading your post, you're just trying to put an underline after the li rows? 重新阅读您的文章后,您只是想在li行后加下划线? If so, you can use the same approach as my answer below, just don't use transform to move it back up so that the border is after the text 如果是这样,您可以使用与我在下面的答案相同的方法,只是不要使用transform将其向上移动,以便边框位于文本之后

 * { margin:0; padding:0; box-sizing:border-box; } ul { list-style: none; } table { border: 1px solid black; position: relative; } td { padding: 1em; } li:not(:last-child):after { content: '\\00a0'; border-bottom: 1px solid black; left: 0; right: 0; position: absolute; } 
 <table> <tr> <td> <ul> <li>foo</li> <li>bar</li> <li>foo</li> </ul> </td> <td> <ul> <li>foo</li> <li>bar</li> <li>foo</li> </ul> </td> <td> <ul> <li>foo</li> <li>bar</li> <li>foo</li> </ul> </td> </tr> </table> 

You can use an absolutely positioned pseudo element on the li draw the line, and make the table relatively positioned so that the line expands the width of the table. 您可以在li上使用绝对定位的伪元素来绘制线条,并使table相对放置,以使线条扩大表格的宽度。

 * { margin:0; padding:0; box-sizing:border-box; } ul { list-style: none; } table { border: 1px solid black; position: relative; } .strike:after { content: '\\00a0'; border-bottom: 1px solid black; left: 0; right: 0; position: absolute; transform: translateY(-50%); } 
 <table> <tr> <td> <ul> <li>foo</li> <li>bar</li> <li>foo</li> </ul> </td> <td> <ul> <li class="strike">foo</li> <li>bar</li> <li>foo</li> </ul> </td> <td> <ul> <li>foo</li> <li>bar</li> <li class="strike">foo</li> </ul> </td> </tr> </table> 

After reading your problem I came to the following conclusion and result, you are facing problem reading cells in row. 阅读完您的问题后,我得出以下结论和结果,您正在面对排成一行的问题阅读单元。 You can achieve this by: 您可以通过以下方法实现此目的:

ul {  
border: 1px solid black;  
}  
row {  
border: 1px solid black;  
}

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

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