[英]How to use CSS :first-child pseudo-element
This is the css I am using to style my menu 这是我用来设置菜单样式的CSS
.vd-menu-item { padding: 0; margin: 0; height: 100%; }
.vd-menu-item:before {content: " | ";}
.vd-menu-litem:first-child:before {content: " ";}
HTML HTML
<div class="vd-menu vd-menu-horizontal">
<ul>
<li class="vd-menu-item"><a href="#" class="vd-menu-link">News</a></li>
<li class="vd-menu-item"><a href="#" class="vd-menu-link">Sports</a></li>
<li class="vd-menu-item"><a href="#" class="vd-menu-link">Finance</a></li>
</ul>
</div>
I want to separate the menu list with "|" 我想用“ |”分隔菜单列表 in between them like 在他们之间像
News | Sports | Finance
So thought of using :before the li. 因此想到了在li之前使用:before。 It works good but the first child, in this case "News" has "|" 效果很好,但是第一个孩子,在这种情况下,“新闻”具有“ |” before it. 在它之前。
| News | Sports | Finance
I tried using first-child but it does not work as expected. 我尝试使用第一个孩子,但无法正常工作。 All the separator "|" 所有分隔符“ |” disappears. 消失。
Can you help? 你能帮我吗?
You could use the :not Selector to make it easier. 您可以使用:not Selector使其更容易。
.vd-menu-item { padding: 0; margin: 0; height: 100%; }
.vd-menu-item:not(:first-child):not(:last-child)::before {content: " | ";}
I hope i helped you out :) 我希望我能帮到你:)
看来您的代码中有错别字: .vd-menu-litem:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.