简体   繁体   English

如果列表项分成两行,则需要使用全宽度的顶部边框

[英]List items need a full width top border if they break into two lines

I have a challenge with a menu of list items. 我有一个列表项菜单的挑战。 The designer wants to add a line above the items if they break into two lines (in smaller screens). 如果项目分成两行(在较小的屏幕中),则设计师希望在项目上方添加一行。 The line should span 100% of the ul width, even though the the second line of list items are shorter. 即使第二行列表项较短,该行也应跨越ul宽度的100%。 It should look like this image - only with the grey line above the list items. 它看起来应该像这张图片-仅在列表项上方显示灰线。

在此处输入图片说明

I have fiddled with it here trying to use a :pseudo element , but still no luck in getting the grey line of the second row take up 100% of the width. 我在这里尝试使用:pseudo element摆弄它 ,但是让第二行的灰线占据宽度的100%仍然没有运气。

Any ideas? 有任何想法吗?

One possible solution sis to make the pseudo-element really big. 一种可能的解决方案是使伪元素真正变大。

li:before {
  content: " ";
  position: absolute;
  top: 0;
  left: 0;
  width: 2000px;
  height: 1px;
  border-bottom: 2px solid #ccc;
  z-index: 1;
}

The designer wants to add a line above the items if they break into two lines (in smaller screens). 如果项目分成两行(在较小的屏幕中),则设计师希望在项目上方添加一行。

Note: Since CSS can't detect line breaking this would always apply..so you'd have to apply this in a media query. 注意:由于CSS不能检测到换行符,因此此方法始终适用。因此您必须在媒体查询中应用此方法。

 ul { list-style: none; margin: 0; overflow: hidden; } li { display: inline-block; margin-right: 2px; padding: 5px; position: relative; z-index: 2; } li:before { content: " "; position: absolute; top: 0; left: 0; width: 2000px; height: 1px; border-bottom: 2px solid #ccc; z-index: 1; } div { padding: 5px; width: 75%; margin: auto; overflow: hidden; } 
 <div> <ul> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> </ul> </div> 

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

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