HTML/CSS笔试(四个代码题)

一、使用flexbox实现居中布局

要求:创建一个包含多个元素的容器。
使用 Flexbox 确保这些元素在水平和垂直方向上都居中。

<!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>flex居中布局</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        .father {
            display: flex;
            width: 300px;
            height: 300px;
            justify-content: center;
            align-items: center;
            background-color: pink;
            margin: 100px auto;
        }

        .son {
            width: 100px;
            height: 100px;
            background-color: #fff;
        }
    </style>
</head>

<body>
    <div class="father">
        <div class="son"></div>
    </div>
</body>

</html>

二、实现一条0.5像素的竖线/横线。

要求:实现一条0.5像素的竖线/横线。

<!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>实现0.5线</title>
    <style>
        .line {
            position: absolute;
            left: 0;
            top: 10px;
            width: 100%;
            height: 1px;
            background-color: #000000;
            transform: scaleY(.5);
        }

        .line1 {
            position: relative;
            top: 20px;
            width: 100%;
            height: 1px;
            background-color: #000000;
        }
    </style>

</head>

<body>
    <div class="line"></div>
    <div class="line1"></div>
</body>

</html>

三、使用 CSS 动画创建一个呼吸效果。

要求:让一个元素在呼吸的过程中改变透明度或颜色。动画应该是无限循环的。

<!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>呼吸效果渐变</title>
    <style>
        .container {
            width: 50px;
            height: 50px;
            z-index: 999;
            position: absolute;
            bottom: 20px;
            right: 10px;
            background-color: #ff5c33;
            color: #ffffff;
            border-radius: 50%;
            text-align: center;
            line-height: 50px;
            cursor: pointer;
            -webkit-animation: mymove 1s 1, mymovecolor 3s linear 1s infinite normal;
            animation: mymove 1s 1, mymovecolor 3s linear 1s infinite normal;
            display: table;
            border: 8px solid #ffffff;
        }

        @keyframes mymove {
            from {
                bottom: 0;
            }

            to {
                bottom: 20px;
            }

            from {
                opacity: 0;
            }

            to {
                opacity: 1;
            }
        }


        @keyframes mymovecolor {
            50% {
                background-color: #ff5c33;
            }

            50% {
                border: 8px solid #f3967e;
            }
        }
    </style>
</head>

<body>
    <div class="container">
        加入
    </div>
</body>

</html>

四、使用 CSS 实现一个带有阴影的卡片效果。

要求:创建一个卡片,卡片有适当的间距。鼠标悬停在卡片上时,产生阴影效果。

<!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>鼠标悬停阴影效果</title>
    <style>
        .box {
            margin-left: 200px;
            margin-top: 200px;
            width: 200px;
            height: 200px;
            background-color: pink;
        }

        .box:hover {
            box-shadow: 10px 10px 15px 0 rgba(0, 0, 0, 0.24);
        }
    </style>
</head>

<body>
    <div class="box"></div>
</body>

</html>
  • 25
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值