Icodethis挑战:30-Day Roadmap 之 Basics

Day01-Basics

实现样版

在这里插入图片描述

思路

三个按钮TYPOGRAPHY、HEADINGS、COLORS,点击按钮进行三个部分的切换(类似👇)
在这里插入图片描述

实现

1. HTML

<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>
    <div class="body">
        <!--  三个点击按钮,用于控制盒子显示/隐藏 -->
        <button class="btnStyle showTyp btn">TYPOGRAPHY</button>
        <button class="btnStyle showHead btn">HEADINGS</button>
        <button class="btnStyle showColor btn">COLORS</button>
        <!-- typography盒子 -->
        <div class="typography selectBox">
            <p style="font-weight:bold">Make me bold</p>
            <p style="font-style:italic">Make me italic</p>
            <p style="font-family:Arial">I'm from the Arial font family!</p>
            <p style="font-family: Times New Roman">And I'm from the Times Roman font family!</p>
            <p style="text-decoration: underline">Make this text underline</p>
            <p style="text-decoration-line: line-through">And put a line throung this one</p>
        </div>
        <!-- headings盒子 -->
        <div class="headings selectBox">
            <h1>This is a h1 tag</h1>
            <h2>This is a h2 tag</h2>
            <h3>This is a h3 tag</h3>
        </div>
        <!-- colors盒子 -->
        <div class="colors selectBox">
            <div class="colorBox">
                <p style="Color:orange">Color me orange!</p>
                <div class="orangeBlock"></div>
            </div>
            <div class="colorBox">
                <p style="Color:purple">Color me purple!</p>
                <div class="purpleCircle"></div>
            </div>
        </div>
    </div>
</body>

</html>

2. CSS样式

/* 总体样式 */
.body {
    width: 450px;
    margin: 15px auto;
}

div {
    margin: 30px 0;
}
/* 选择盒 */
.selectBox {
    padding: 10px;
    display: none;
    border: 3px dotted black;
    border-radius: 10px;
}

/* 按钮样式 */
.btn {
    width: 130px;
    height: 50px;
    background-color: rgb(70, 33, 171);
    border-radius: 5px;
    font-weight: bold;
    font-family: Arial;
    color: white;
}

.btn:hover {
    background-color: rgb(134, 108, 220);
}

.btn:active {
    background-color: rgb(207, 196, 241);
}


/* 颜色盒样式 */
.colorBox {
    width: 150px;
    margin: 0 auto;
}

.orangeBlock {
    width: 100px;
    height: 100px;
    display: inline-block;
    cursor: pointer;
    border: 1px dotted black;
}

.orangeBlock:active {
    background-color: orange;
}

.purpleCircle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    display: inline-block;
    cursor: pointer;
    border: 1px dotted black;
}

.purpleCircle:active {
    background-color: purple;
}

3. JS逻辑

const typBlock = document.querySelector(".typography")
const headBlock = document.querySelector(".headings")
const colorBlock = document.querySelector(".colors")

const showTyp = document.querySelector(".showTyp")
const showHead = document.querySelector(".showHead")
const showColor = document.querySelector(".showColor")

showTyp.addEventListener('click', () => {
 closeAllBlock()
 typBlock.style.display = "block"
})

showHead.addEventListener('click', () => {
 closeAllBlock()
 headBlock.style.display = "block"
})

showColor.addEventListener('click', () => {
 closeAllBlock()
 colorBlock.style.display = "block"
})

const closeAllBlock = function () {
 colorBlock.style.display = "none"
 headBlock.style.display = "none"
 typBlock.style.display = "none"
}

笔记

1. CSS字体样式

在这里插入图片描述

2. 字体下划线样式

text-decoration:字体划线修饰
text-decoration-line:字体划线位置等

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

白帆白女士

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

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

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

打赏作者

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

抵扣说明:

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

余额充值