在个人简介页面中添加动态模态框,要求包含模态框页头、模态框体、模态框页脚、关闭按钮。
时间: 2023-07-10 11:21:53 浏览: 74
好的,这是一个比较常见的需求,可以通过以下步骤来实现:
1. 在个人简介页面中添加一个按钮,例如:
```html
<button id="open-modal-btn">打开模态框</button>
```
2. 创建一个模态框的 HTML 结构,例如:
```html
<div class="modal">
<div class="modal-header">
<h3>模态框页头</h3>
<button class="close-modal-btn">×</button>
</div>
<div class="modal-body">
<p>模态框体</p>
</div>
<div class="modal-footer">
<button class="close-modal-btn">关闭</button>
</div>
</div>
```
3. 使用 CSS 样式将模态框隐藏,例如:
```css
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
background-color: #f0f0f0;
border-bottom: 1px solid #ccc;
}
.modal-body {
padding: 10px;
}
.modal-footer {
display: flex;
justify-content: flex-end;
align-items: center;
padding: 10px;
background-color: #f0f0f0;
border-top: 1px solid #ccc;
}
.close-modal-btn {
border: none;
background-color: transparent;
font-size: 20px;
cursor: pointer;
}
```
4. 使用 JavaScript 代码控制模态框的显示和隐藏,例如:
```javascript
const openModalBtn = document.getElementById('open-modal-btn');
const closeModalBtns = document.querySelectorAll('.close-modal-btn');
const modal = document.querySelector('.modal');
openModalBtn.addEventListener('click', () => {
modal.style.display = 'block';
});
closeModalBtns.forEach((btn) => {
btn.addEventListener('click', () => {
modal.style.display = 'none';
});
});
```
这样就可以在个人简介页面中添加一个动态模态框了,包含模态框页头、模态框体、模态框页脚、关闭按钮。
阅读全文
相关推荐















