Bootstrap 的输入按钮组插件(Button Group)允许你将多个按钮组合成一个单一的元素。默认情况下,按钮组中的按钮会共享边框和圆角,以创建一个统一的外观。如果你隐藏了第二个按钮并希望显示第一个按钮的圆角,可以通过自定义 CSS 来实现。
border-radius
属性可以设置元素的圆角。.btn-group
类。.btn-group-vertical
类。如果你隐藏了第二个按钮并希望第一个按钮显示完整的圆角,可以通过以下步骤解决:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Button Group Example</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<style>
.btn-group > .btn:first-child:not(.d-none) {
border-top-right-radius: .25rem;
border-bottom-right-radius: .25rem;
}
.btn-group > .btn:last-child.d-none + .btn {
border-top-left-radius: .25rem;
border-bottom-left-radius: .25rem;
}
</style>
</head>
<body>
<div class="container mt-5">
<div class="btn-group">
<button type="button" class="btn btn-primary">Button 1</button>
<button type="button" class="btn btn-secondary d-none">Button 2</button>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
.d-none
类隐藏第二个按钮。通过这种方式,你可以灵活地控制按钮组的视觉效果,使其适应不同的设计需求。
领取专属 10元无门槛券
手把手带您无忧上云