水滴效果#css#html

240 阅读1分钟

这是一个包含水滴动画效果的HTML页面。解释一下页面的结构和CSS样式。

这个HTML页面的结构如下:

  • <html>:此标签为HTML文档的根标签。
  • <head>:这个标签包含了一些关于文档的元数据,以及一些引用的外部文件,如CSS样式和JavaScript脚本。
  • <meta>:这个标签用于设置网页的视口(viewport),其中content属性指定了视口的宽度和初始缩放比例。
  • <title>:这个标签设置网页的标题。
  • <style>:这个标签包含了网页的CSS样式。

解释一下CSS部分的代码:

  • *{margin: 0; padding: 0; box-sizing: border-box;}:这是一个通用选择器,将所有元素的外边距和内边距设置为0,并将盒模型设置为包括边框和内边距在内的总宽度和高度。
  • body{...}:设置body元素的样式,其中包括将宽度和高度设置为整个视口的宽度和高度,显示方式设置为弹性布局,并将内容水平居中,背景颜色设置为aqua。
  • #water{...}:设置id为water的元素(这里是一个<div>)的样式。设置了margin-top来将其向下移动,设置了宽度和高度,用border-radius设置了边框的圆角,用box-shadow设置了盒子的阴影效果,用animation设置了动画效果。
  • #water::after#water::before:这两个选择器分别设置了#water元素的伪元素。它们的样式类似,但位置和大小不同,用于表示水滴上的两个小水珠。它们使用了绝对定位(position:absolute)。
  • @keyframes action:这是一个动画关键帧声明,定义了一个名为action的动画。这个动画在不同的百分比(25%,50%,100%)下,通过修改#water元素的边框圆角属性实现形状的变化。
<head>
    <meta name="viewport" content="width=device-widtn, initial-scale=1.0">
    <title>水滴</title>
    <style>   <!--默认样式 -->
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body{
            width: 100vw;
            height: 100vh;
            display: flex;
            justify-content: center;  
            background-color: aqua;
        }
        #water{
            margin-top: 200px;
            width: 300px;
            height: 300px;
        
            border-radius: 38% 62% 46% 54% / 48% 42% 58% 52%  ;
            box-shadow: inset 10px 20px 30px rgba(0, 0, 0, 0.5),
                        10px 10px 20px rgba(0, 0, 0, 0.3),
                        15px 15px 30px rgba(0, 0, 0, 0.05),
                        inset -10px -10px 15px rgba(255, 255, 255, 0.8);
            animation: action 2s linear infinite alternate;
        }
        #water::after{
            content: '';
            width: 20px;
            height: 20px;
            position:absolute;
            top:240px;
            left: 48%;
            background-color: aliceblue;
            border-radius: 50% 50% 63% 37% / 54% 63% 37% 46% ;
        }
        #water::before{
            content: '';
            width: 10px;
            height: 10px;
            position:absolute;
            top: 265px;
            left: 47%;
            background-color: aliceblue;
            border-radius: 42% 58% 63% 37% / 63% 71% 29% 37% ;
        }
        @keyframes action {
            25%{
                border-radius:40% 60% 52% 48% / 48% 46% 54% 52%  ;
            }
            50%{
                border-radius:45% 55% 63% 37% / 41% 56% 44% 59%  ;
            }
            100%{
                border-radius: 54% 46% 66% 34% / 37% 59% 41% 63% ;
            }
        }
    </style>
</head>
<body>
    <div id="water"></div>
</body>
</html>