用bootstrap 和jq 写一个底部反圆角的盒子
时间: 2024-03-21 10:40:32 浏览: 20
可以使用 Bootstrap 和 jQuery 来实现一个底部反圆角的盒子,具体步骤如下:
1. 创建 HTML 结构,包含一个 div 元素作为容器,以及一个按钮元素。
```html
<div class="footer">
<button class="btn btn-primary">Click Me</button>
</div>
```
2. 添加 CSS 样式,设置容器的背景颜色、边框、圆角和位置。
```css
.footer {
background-color: #f8f9fa;
border: 1px solid #e2e3e5;
border-radius: 0 0 10px 10px;
position: fixed;
bottom: 0;
width: 100%;
padding: 20px 0;
}
```
3. 使用 jQuery 将容器的底部两个角设置为直角,并且添加一个点击事件,点击按钮时切换底部两个角的样式。
```javascript
$(document).ready(function() {
$('.footer').click(function() {
$(this).toggleClass('rounded-0');
});
});
```
完整代码如下:
```html
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Footer</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.5.3/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.5.3/js/bootstrap.min.js"></script>
<style>
.footer {
background-color: #f8f9fa;
border: 1px solid #e2e3e5;
border-radius: 0 0 10px 10px;
position: fixed;
bottom: 0;
width: 100%;
padding: 20px 0;
}
</style>
</head>
<body>
<div class="footer">
<button class="btn btn-primary">Click Me</button>
</div>
<script>
$(document).ready(function() {
$('.footer').click(function() {
$(this).toggleClass('rounded-0');
});
});
</script>
</body>
</html>
```
这样就实现了一个底部反圆角的盒子,并且可以通过点击按钮来切换底部两个角的样式。