浮动列表中的行分隔符
这就是我想要实现的目标。
[Item 0] [Item 1] [Item 2] [Item 3]
- - - - - - - - - - - - - - - - - - - - -
[Item 4] [Item 5] [Item 6] [Item 7]
- - - - - - - - - - - - - - - - - - - - -
[Item 8] [Item 9] [Item10] [Item11]
当前代码:
<ul><li>[Item 0]</li>...</ul>
li { float: left; }
是的,火箭科学。它是一个带有行分隔符的浮动列表。如果分隔符是实线,则可以通过边框/背景来实现。但它是一条自定义虚线,因此背景不会在项目之间连续流动。
是否有一些我不知道的很酷的 CSS 魔法可以做到这一点,或者我是否必须为每一行使用单独的
?This is what I want to achieve.
[Item 0] [Item 1] [Item 2] [Item 3]
- - - - - - - - - - - - - - - - - - - - -
[Item 4] [Item 5] [Item 6] [Item 7]
- - - - - - - - - - - - - - - - - - - - -
[Item 8] [Item 9] [Item10] [Item11]
Current code:
<ul><li>[Item 0]</li>...</ul>
li { float: left; }
Yes, rocket science. It's a floated list with row separators. If the separator was a solid line, it could be achieved with border/background. But it's a custom dashed line, so a background wouldn't flow continuously between the items.
Is there some cool CSS wizardry to do this that I'm not aware of, or do I have to use separate <ul>
for each row?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我可能完全误解了,但这不起作用吗?
http://jsfiddle.net/csswizardry/85UZz/3/
编辑:< /strong> 这是最后一行被遮盖的图像 http://jsfiddle.net/csswizardry/85UZz/4/
I may have totally misunderstood, but would this not work?
http://jsfiddle.net/csswizardry/85UZz/3/
EDIT: Here's the image masked out on the last row http://jsfiddle.net/csswizardry/85UZz/4/
您可以在每行的第四个 li 之后添加一个跨度,然后按照您想要的方式设置样式,但请确保设置
display: inline-block;
you could add a span after the 4th li on each row then style that the way you want it, but make sure to set
display: inline-block;
我能想到的唯一魔法就是类似的东西。基本上使用
nth-child(n)
来达到预期的效果。Only wizardry I can think of would be something like this. Basically using
nth-child(n)
to achieve the desired effect.这是您所要求的超级基本版本...
使用一些 JS 也可以工作,迭代一些内容来表示每个 li 放入具有特定样式的跨度中。
希望这能有所帮助并澄清。
here is a super basic version of what your asking...
using some JS could work as well, iterate something to say every # of li's put in a span that has a specific style.
hope this helps and clarifies.
我用
:before
选择器解决了这个问题。I solved this with the
:before
selector.