CSS笔记(二)类名复用

这里我通过两张不同位置的卡片来实现效果

  • 代码
<!DOCTYPE html>
<html>
    <head>
        <style>
            /*设置画布*/
            body{
                /* 方便排列与对齐*/
                display: flex; 
                /*画布布满整个窗口*/
                height: 100vh;
                /*水平居中*/
                justify-content: center;

                /*垂直居中*/
                align-items: center;
                /* 设置比较暗的背景色*/
                background-color: rgba(47,48,49,0.9);
            }
            /*设置活动区域*/
            .container{
                display: flex;
                justify-content: center;
                align-items: center;
                /*给子元素提供相对描点*/
                position: relative;
                width: 500px;
                height: 500px;
            }
            .card{
                
                /*表示该元素会以相对锚点改变位置*/
                position: absolute;
                width: 150px;
                height: 200px;
                display: flex;
                justify-content: center;
                align-items: center;
                font-size: 30px;
                font-weight: bold;
                background-color: #00ff44;
                
                /*设置阴影,切记参数之间不要有逗号*/
                box-shadow: 0px 8px 8px rgba(0,0,0,0.8);
            }
            .card1{
                left: 0;
                top:0;
            }
            .card2{
                left:300;
                top:100p;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="card card1">Card1</div>
            <div class="card card2 ">Card2</div>
        </div>
    </body>
</html>
  • 效果:
  • 在这里插入图片描述
    显然这里我们让卡片元素具有了两个类cardcard1,我们把相对锚点的位置信息放到card1中,这样我们相当于把两个类合成一个类在用,不过可以复用的类我们就摘出去用,需要对每个卡片设置的部分就放到对应的类里。这样给我们的开发带来了极大的便利。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值