简体   繁体   English

如何使用 CSS 删除特定边框

[英]How to remove a specific border with CSS

I am trying to remove the last border on the right as seen in the picture below.我正在尝试删除右侧的最后一个边框,如下图所示。 How would I go about in removing this?我将如何 go 删除这个?

在此处输入图像描述

My code:我的代码:

 #headerlinks li, a { display: inline-flex; text-decoration: none; color: black; border-right: solid 1px black; }
 <div id="headerlinks"> <nav> <ul> <li><a href="#"> Contact us </a></li> <!-- need to link and create contact us html --> <li><a href="#">Accessibility</a></li> <li></li><a href="#">Login</a></li> </ul> </nav> </div>

You should add style for last of li that is #headerlinks li:last-child, a您应该为最后一个 li 添加样式,即#headerlinks li:last-child, a

 #headerlinks li, a { display: inline-flex; text-decoration: none; color: black; border-right: solid 1px black; } #headerlinks li:last-child, a { border-right: none; }
 <div id="headerlinks"> <nav> <ul> <li><a href="#"> Contact us </a></li> <!-- need to link and create contact us html --> <li><a href="#">Accessibility</a></li> <li></li><a href="#">Login</a></li> </ul> </nav> </div>

If you want to remove border from all a tag then simply remove border-right:solid 1px black from css如果要从所有标签中删除边框,则只需从 css 中删除 border-right:solid 1px black

 #headerlinks li, a { display: inline-flex; text-decoration: none; color: black; border-right: solid 1px black;//remove this if border not req. }
 <div id="headerlinks"> <nav> <ul> <li><a href="#"> Contact us </a></li> <:-- need to link and create contact us html --> <li><a href="#">Accessibility</a></li> <li></li><a href="#" style="border;none;">Login</a></li> </ul> </nav> </div>

You can use the selector.您可以使用选择器。 :last-child

 #headerlinks li a { display: inline-flex; text-decoration: none; color: black; } #headerlinks li:not(:last-child) a { border-right: solid 1px black; }
 <div id="headerlinks"> <nav> <ul> <li><a href="#"> Contact us </a></li> <!-- need to link and create contact us html --> <li><a href="#">Accessibility</a></li> <li><a href="#">Login</a></li> </ul> </nav> </div>

You can use the "last-child" property in css, to remove border from last element.您可以使用 css 中的“last-child”属性来删除最后一个元素的边框。 Also remove extra closing "li" element from html.还要从 html 中删除额外的关闭“li”元素。

 #headerlinks li, a { display: inline-flex; text-decoration: none; color: black; border-right: solid 1px black; } #headerlinks li:last-child, a { border-right: none; }
 <div id="headerlinks"> <nav> <ul> <li><a href="#"> Contact us </a></li> <li><a href="#">Accessibility</a></li> <li><a href="#">Login</a></li> </ul> </nav> </div>

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

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