css - Bootstrap - 在活动 btn-check 上添加三角形指示器
问题描述
我有一个 Bootstrap 5 应用程序。在这个应用程序中,我在一个组中有三个不同大小的按钮。按钮组定义如下:
<div class="btn-group d-flex">
<button class="btn btn-info py-4">Sunday</button>
<button class="btn btn-info py-4">Monday</button>
<button class="btn btn-info py-4">Tuesday</button>
</div>
当我选择其中一个按钮时,我可以看到应用了以下 CSS 类:
.btn-check:focus + .btn-info, .btn-info:focus
当用户选择其中一个按钮时,我想在按钮上应用一个居中的“三角形”。我的问题是,如何在具有焦点的按钮上添加居中三角形指示器?
为了演示,此时,我的按钮如下所示:
+-------------+
| Day of Week |
+-------------+
However, I when a button is selected, I want them to look like this:
+------^------+
| Day of Week |
+-------------+
解决方案
你可以试试这个:
我只是在添加向上箭头的按钮上使用了 after。
.btn-info{
border-top:1px dashed black;
border-bottom:1px dashed black;
border-right:1px dotted black;
border-left:1px dotted black;
position:relative;
z-index:0;
background-color:white;
padding:5px;
}
.btn-info:focus-within::after{
content:'^';
position:absolute;
height:5px;
width:5px;
bottom:100%;
left:50%;
background:white;
padding-bottom:5px;
}
<div class="btn-group d-flex">
<button class="btn btn-info py-4">Sunday</button>
<button class="btn btn-info py-4">Monday</button>
<button class="btn btn-info py-4">Tuesday</button>
</div>
推荐阅读
- javascript - 如何在 react.js 的地图中使用 if?
- nginx - SSL 与上游握手时 Nginx 错误上游超时(110:连接超时)
- regex - 如何使用正则表达式替换字符串的给定索引
- java - 在开始时加载 SQL 数据
- amazon-web-services - 通过 NodeJS 在 AWS Lambda 上使用量角器
- c - 在C中的函数中传递不同的数据成员
- video - h264 提取帧仅适用于某些操作系统/ffmpeg 版本
- javascript - 单击时可调整大小的侧边导航展开
- python - 即使 runtime.txt 正确,使用 $ git push heroku master 时也会出错
- javascript - 访问数组列表中的对象