【前端】CSS入门第二天

案例1:

  1. 绘制3个变长为20px的正方形,颜色分别为 green black white
  2. 最外层盒子给阴影 颜色purple,XY轴各偏移10px,模糊度10px
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box {
        width: 100px;
        height: 100px;
        border-radius: 15px;
        background-color: pink;
        box-shadow: purple 10px 10px 10px;
    }

    .square1 {
        width: 20px;
        height: 20px;
        background-color: green;
    }

    .square2 {
        width: 20px;
        height: 20px;
        background-color: black;
    }

    .square3 {
        width: 20px;
        height: 20px;
        background-color: white;
    }
</style>

<body>
    <div class="box">
        <div class="square1"></div>
        <div class="square2"></div>
        <div class="square3"></div>
    </div>
</body>

</html>

知识点:

  • 盒子阴影 box-shadow: X轴偏移度 Y轴偏移度 模糊度 模糊范围
  • 明白 div 是块状元素,正常情况下无法排列在同一行

案例2:

  1. 利用通配符去除页面预设样式
  2. 使三个正方形在同一行排列
  3. 水平且垂直居中
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    /* 通配符 */
    * {
        margin: 0;
    }

    .box {
        width: 100px;
        height: 100px;
        border-radius: 15px;
        background-color: pink;
        box-shadow: purple 10px 10px 10px;
    }

    .squareBox {
        /* 专有名词叫弹性布局,是最常用的布局之一 */
        display: flex;
        flex-direction: row;
        /* 下面两行代码实现水平垂直居中 */
        justify-content: center;
        align-items: center;
    }

    .square1 {
        width: 20px;
        height: 20px;
        background-color: green;
    }

    .square2 {
        width: 20px;
        height: 20px;
        background-color: black;
    }

    .square3 {
        width: 20px;
        height: 20px;
        background-color: white;
    }
</style>

<body>
    <div class="box">
        <div class="squareBox">
            <div class="square1"></div>
            <div class="square2"></div>
            <div class="square3"></div>
        </div>
    </div>
</body>

</html>

知识点:

  • 通配符
  • 弹性布局 display: flex
  • 水平垂直居中的代码公式
.父盒子{
	display: flex;
	justify-content: center;
	align-items: center;
}

思考:

  1. 如何让三个正方形在盒子中水平居中显示?
  2. 如何让三个盒子间距合适的平铺在同一列?

提示:

  • 去MDN、菜鸟教程搜搜看
  • 第二个问题跟 justify-content 的一个属性值有关

最终实现效果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值