寒假学习记录8:HTML小知识

本文介绍了HTML中的表单元素如文本框、复选框,以及CSS样式,特别关注了box-sizing属性的应用、列表项的UI设计和主题切换功能。展示了如何使用CSS实现响应式设计和用户界面定制。
摘要由CSDN通过智能技术生成
后续会更新
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>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

博丽七七

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值