
批改狀態(tài):合格
老師批語(yǔ):彈層有點(diǎn)任性了
浮動(dòng)本質(zhì)是為了解決圖文并排顯示的問題
浮動(dòng)要解決的兩個(gè)問題:
1.浮動(dòng)元素的高度對(duì)于它的包含塊不可見
2.浮動(dòng)元素可以BFC塊使它不影響到后面的元素布局
左浮動(dòng):float:left; 右浮動(dòng):float:right;
清除浮動(dòng):clear:both;
定位的屬性是position
定位類型:靜態(tài)定位static,相對(duì)定位relative,絕對(duì)定位absolute,固定定位fixed。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>模態(tài)框</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
header{
background-color: lightgreen;
padding: 0.5em 2em;
overflow: hidden;
}
header h2{
float: left;
}
header button{
float: right;
width: 10em;
height: 2.5em;
}
.modal .modal-backdrop{
background-color: rgb(0,0,0,0.5);
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.modal .modal-body{
padding: 1em;
min-width: 25em;
border: 1px solid #000;
background: linear-gradient(to right, lightcyan, #fff);
position: fixed;
top:10em;
left:30em;
right: 30em;
}
.modal form table {
width: 80%;
}
.modal form table caption {
font-weight: bold;
margin-bottom: 1em;
}
.modal form table {
text-align: center;
}
.modal-body{
position: relative;
}
.modal-body .close{
position: absolute;
width: 4em;
height: 2em;
top: 1em;
right: 1em;
}
.modal{
display: none;
}
</style>
</head>
<body>
<header>
<h2>php中文網(wǎng)</h2>
<button>消息</button>
</header>
<div class="modal">
<div class="modal-backdrop"></div>
<div class="modal-body">
<button class="close">關(guān)閉</button>
<form action="">
<table>
<caption>消息列表</caption>
<tr>
<th>系統(tǒng)消息</th><th>好友消息</th>
</tr>
<tr>
<td>xxxxx</td><td>yyyyy</td>
</tr>
</table>
</form>
</div>
</div>
<script>
const btn = document.querySelector('header button');
const modal = document.querySelector('.modal');
const close = document.querySelector('.close');
btn.addEventListener('click', setModal, false);
close.addEventListener('click', setModal, false);
function setModal(ev) {
ev.preventDefault();
let status = window.getComputedStyle(modal, null).getPropertyValue('display');
modal.style.display = status === 'none' ? 'block' : 'none';
}
</script>
</body>
</html>
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)