1 Star 0 Fork 0

小白菜。 / css-study-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

CSS 学习

一个 css 初学者建立的仓库,用来记录 css 的学习。

从实例中感悟 css 的奥妙

1、交错动画

:tea: 通过设置不同的延迟时间,达到动画交错播放的效果。

:coffee: 可以通过css动画延迟(delay)属性来实现。

    <div class="loading">
        <div class="dot bg1"></div>
        <div class="dot bg2"></div>
        <div class="dot bg3"></div>
        <div class="dot bg4"></div>
        <div class="dot bg5"></div>
    </div>

    <style>
        body {
            display: flex;
            height: 100vh;
            justify-content: center;
            align-items: center;
        }

        .loading {
            display: flex;
        }

        .dot {
            position: relative;
            width: 2em;
            height: 2em;
            margin: 0.8em;
            border-radius: 50%;
        }

        .dot::before {
            position: absolute;
            content: "";
            width: 100%;
            height: 100%;
            background: inherit;
            border-radius: inherit;
            animation: wave 2s ease-out infinite;
        }

        .bg1 {
            background: #7ef9ff; 
        }
        .bg1::before {
            animation-delay: 0.2s;
        }

        .bg2 {
            background: #89cff0;
        }
        .bg2::before {
            animation-delay: 0.4s;
        }

        .bg3 {
            background: #4682b4;
        }
        .bg3::before {
            animation-delay: 0.6s;
        }

        .bg4 {
            background: #0f52ba;
        }
        .bg4::before {
            animation-delay: 0.8s;
        }

        .bg5 {
            background: #000080;
        }
        .bg5::before {
            animation-delay: 1s;
        }


        @keyframes wave {
            50%,
            75% {
                transform: scale(2.5);
            }

            80%,
            100% {
                opacity: 0;
            }
        }
    </style>

:loudspeaker: ::before,创建一个伪元素,其将成为匹配选中元素中的第一个子元素。通常通过 content 属性来为元素添加修饰性的内容。此元素默认为行内元素。

:zap: 很多动画效果都需要使用 ::before::after

/* Add a heart before links */
a::before {
  content: "♥";
}

2、字体单位大小

CSS 中存在很多可以描述单位的尺寸,比如 pxemremvwvh等。

2.1、CSS长度单位

  • 绝对长度单位,表示一个固定值,不会改变,不利于页面渲染

    • in:英寸
    • cm:厘米
    • mm:毫米
  • 相对长度单位,随着参考值的变化而变化。

    • px:像素

    • em:元素字体高度

      body里声明font-size:62.5%。即全局声明1em = 16px * 62.5% = 10px

      之后可以把em当做px使用。当然此时,1em = 10px

      如果在父容器里说明了font-size:20px,那么在子容器里的1em就等于20px

    • %:百分比

    • rem:根元素的font-size

      html {
        font-size: 10px; /* 不建议设置 font-size: 62.5%; 在 IE 9-11 上有偏差,具体表现为 1rem = 9.93px。 */
      }
      
      .sqaure {
        width: 5rem;  /* 50px */
        height: 5rem; /* 50px */
      }
      
      <style>
        html{ font-size: 20px; }
        body{ 
          font-size: 1.4rem;  /* 1rem = 28px */
          padding: 0.7rem;  /* 0.7rem = 14px */
        } 
        div{
          padding: 1em;  /* 1em = 28px */
        }
        span{
          font-size:1rem;  /* 1rem = 20px */
          padding: 0.9em;  /* 1em = 18px */
        }
      </style>
      
      <html>
        <body>
          <div>   
            <span></span>  
          </div>
        </body>
      </html>
    • vw:视窗宽度,1vw = 视窗宽度的1%

    • vh:视窗高度,1vh = 视窗高度的1%

MIT License Copyright (c) 2024 小白菜。 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

学习css的记录 展开 收起
HTML
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/xbc520/css-study-demo.git
git@gitee.com:xbc520/css-study-demo.git
xbc520
css-study-demo
css-study-demo
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891