后续会更新
form
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
</style>
<body>
<form onsubmit="onSearch(event)">
<div class="search-box">
<input type="text" placeholder="搜索" class="input">
<button type="submit" class="search-button">
<span>提交</span>
</button>
</div>
</form>
<script>
function onSearch(e){
e.preventDefault();
console.log(document.querySelector(".input").value)
}
</script>
</body>
</html>
label
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
li{
list-style: none;
}
li label .action input{
appearance: none;
}
li label {
display: flex;
align-items: center;
}
li label .action{
display: flex;
align-items: center;
}
li label .action i{
width: 30px; height: 15px;
background-color: #ddd;
border-radius: 15px;
position: relative;
}
li label .action i::before{
content: "";
position: absolute;
top: 2.5px; left: 2.5px; width: 10px; height: 10px;
border-radius: 10px;
background-color: #fff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
transition: all 0.5s;
}
li label .action input:checked ~ i::before{
left: calc(100% - 12.5px);
}
li label .action input:checked ~ i{
background-color: #2aa0ff;
}
</style>
<body>
<li>
<label>
<span class="title">Location</span>
<span class="action">
<input type="checkbox">
<i></i>
</span>
</label>
</li>
<li>
<label>
<span class="title">Mode</span>
<span class="action">
<input type="checkbox">
<i></i>
</span>
</label>
</li>
</body>
</html>
box-sizing
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
*{
margin: 0;
padding: 0;
}
.p{
display: flex;
}
.a,.b{
margin-left: 20px;
width: 100px;
height: 100px;
background-color: aqua;
border: 10px solid red;
}
.a{
box-sizing: border-box;
}
</style>
<body>
<div class="p">
<div class="a">
</div>
<div class="b">
</div>
</div>
</body>
</html>
切换主题
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
html[data-theme="dark"] {
--color: #589eff;
}
:root {
--color: #f43032;
}
.a {
color: var(--color);
}
.theme-button {
margin-top: 20px;
}
</style>
<body>
<div class="a">
ajaofja
</div>
<button class="theme-button">切换主题</button>
<script>
(() => {
let button = document.querySelector("button");
let html = document.querySelector("html");
button.addEventListener("click",()=>{
if (html.getAttribute('data-theme') === 'dark') {
html.setAttribute('data-theme', '');
} else {
html.setAttribute('data-theme', 'dark');
}
})
})();
</script>
</body>
</html>