html - 如何在border-bottom 属性中创建圆角线边框?
问题描述
我正在尝试创建一个风格化的下划线,结果我假装它是这样的:
我想要达到的目标:
正如你所看到的,我想要的边界在它的末端是圆形的。但是在这里使用边界底部我到目前为止得到的:
我的代码是这样的:
HTML
<nav class="navbar">
<a id="index" href="#index">Home</a>
<a href="#">Pokedéx</a>
<a href="#">Legendaries</a>
<a href="#">Documentation</a>
</nav>
和 CSS
.navbar > a {
font-size: 1.5rem;
margin: 0px 10px 0px 0px;
text-decoration: none;
color: #212121;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-weight: 400;
}
.navbar > a:target {
border-bottom: 4px solid #212121;
}
所以我想知道的是,是否有办法使边框框的边框(无论它们是底部、顶部、右侧、左侧,都无关紧要)变圆还是有更好的方法来设置此下划线的样式?你会怎么做?
非常感谢。
解决方案
我通常::after
为此使用伪元素
.navbar > a {
position: relative; /* This is the reference for the after psuedo-element*/
font-size: 1.5rem;
margin: 0px 10px 0px 0px;
text-decoration: none;
color: #212121;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-weight: 400;
}
.navbar > a:target::after {
content: '';
position: absolute;
left: 0;
bottom: -4px; /* Negative height */
width: 100%;
height: 4px; /* Height of border */
background-color: #212121;
border-radius: 5rem; /* This can be any number but is normally set very high for the pill-shape */
}
<nav class="navbar">
<a id="index" href="#index">Home</a>
<a href="#">Pokedéx</a>
<a href="#">Legendaries</a>
<a href="#">Documentation</a>
</nav>
推荐阅读
- java - Spring Boot:日志文件中的非英语字符
- excel - 如何使用 vb-script 在特定范围的 Excel 单元格中添加下拉菜单?
- vue.js - Vue,自动对焦单选按钮
- python - 如何使用 for 循环反转此字符串
- sql-server - 当我使用 Merge Join 有多个平面文件时如何在 SSIS 中进行转换?
- vb.net - 在尊重 mvvm 的同时使用列表框的 autoscoll
- python - 为什么keras模型训练后会变大?
- javascript - 防止随机生成的位置剪裁画布边缘
- python - 如何从 Elasticsearch 7.XX 中获取超过 10000 条记录
- data-science - ML 中的二项式和多项式分类