Tailwind css系列教程(二)

一、参考属性

https://tailwind.muzhifan.top/
在这里插入图片描述
也可查找官方网站

以下为参考官网及网络上其他文章内容整理:

二、常用属性格式

1、颜色

color:颜色名称

shade:色度,取值范围为 100~900,不可对黑色或白色使用

  • 文本颜色:text-[color]-[shade]

    <p class="text-red-500">Color Red 500</p>
    
  • 背景颜色:bg-[color]-[shade]

    <p class="bg-red-500">BgColor Red 500</p>
    
  • 下划线颜色:underline decoration-[color]-[shade]

    • underline:添加下划线
    <p class="underline decoration-green-500">UlColor Green 500</p>
    
  • 边框颜色:border border-[color]-[shade]

    • border:添加边框
    <input type="text" class="border border-green-500" />
    
  • 间隔颜色:divide-[direct] divide-[color]-[shade]

    • divide-[direct]:添加分隔,direct 表示分隔方向,取值 x-横向、y-纵向
    <div class="divide-y divide-red-500">
      <div>Item 1</div>
      <div>Item 2</div>
      <div>Item 3</div>
    </div>
    
  • 轮廓线颜色:outline outline-[color]-[shade]

    • outline:添加轮廓线
    <button class="outline outline-green-500">OlColor Green 500</button>
    
  • 盒子阴影颜色:shadow-[container] shadow-[color]-[shade(/opacity)]

    • shadow-[container]:添加阴影,container 表示阴影最大宽度

      containerwidth
      sm640px
      md768px
      lg1024px
      xl1280px
      2xl1536px
    • (/opacity):透明度,默认 100,取值 0~100

    <div class="shadow-lg shadow-red-500/20">SdColor Red 500</div>
    
  • 强调颜色:accent-[color]-[shade]

    <input type="checkbox" class="accent-green-500" checked />
    
  • 自定义颜色:-[(#xxxxx|rgb(r,g,b)|name)]

    • 十六进制、RGB、名称
    <p class="text-[#4682B4]">Color #4682B4</p>
    <p class="text-[rgb(46,130,180)]">Color RGB(46,130,180)</p>
    <p class="text-[steelblue]">Color Steelblue</p>
    
2、容器与间距
  • 容器

    <div class="container mx-auto">
     。。。。。
    </div>
    
    • container:标记为容器
    • mx-auto:x 轴方向(横向),外边距(margin)自动
  • 外边距:m?-[number]

    • m?m-Margin、mt-MarginTop、ml-MarginLeft、mr-MarginRight、mb-MarginBottom
    number=number * 0.25rem=number * 4px
    如:m-2 意思为 margin: 0.5rem
    
    <div class="bg-red-200 m-2">Margin 2</div>
    <div class="bg-red-200 ml-2">Margin Left 2</div>
    <div class="bg-red-200 m-[20px]">Margin 20px</div>
    
  • 内边距:p?-[number]

    • p?p-Padding、pt-PaddingTop、pl-PaddingLeft、pr-PaddingRight、pb-PaddingBottom
    • number=number * 0.25rem=number * 4px
    <div class="bg-red-200 mb-1 p-2">Padding 2</div>
    <div class="bg-red-200 mb-1 pl-2">Padding Left 2</div>
    <div class="bg-red-200 mb-1 p-[20px]">Padding 20px</div>
    
  • 间距:(-)space-[direct]-[number]

    • (-):负间距
    • direct:间隔方向,取值 x-横向、y-纵向
    • number=number * 0.25rem=number * 4px
    <div class="flex space-x-2">
      <div>Item 1</div>
      <div>Item 2</div>
      <div>Item 3</div>
    </div>
    <div class="flex flex-col space-x-2">
      <div>Item 1</div>
      <div>Item 2</div>
      <div>Item 3</div>
    </div>
    
    • flex:采用 Flex 布局
    • flex-col:Flex 布局纵向

3、版面设计

  • 字体:font-[family]

    <div class="font-sans">Font Sans</div>
    
    • 自定义字体族配置

      <head>
        <script>
          tailwind.config = {
            theme: {
              fontFamily: {
                sans: ["Inter", "sans-serif"],
                serif: ["Inter", "serif"],
                mono: ["Inter", "monospace"]
              }
            }
          }
        </script>
      </head>
      
  • 字号:text-[size]

    <div class="text-xs">Text Extra Small</div>
    <div class="text-sm">Text Small</div>
    <div class="text-base">Text Base</div>
    <div class="text-lg">Text Large</div>
    <div class="text-xl">Text Extra Large</div>
    <div class="text-2xl">Text 2 Extra Large</div>
    <div class="text-3xl">Text 3 Extra Large</div>
    
  • 字重:font-[weight]

    <div class="font-light">Font Light</div>
    <div class="font-normal">Font Normal</div>
    <div class="font-medium">Font Medium</div>
    <div class="font-semibold">Font Semibold</div>
    <div class="font-bold">Font Bold</div>
    
  • 字距:tracking-[space]

    <div class="tracking-tight">Tracking Tight</div>
    <div class="tracking-normal">Tracking Normal</div>
    <div class="tracking-wide">Tracking Wide</div>
    
  • 文本对齐:text-[direct]

    <div class="text-left">Text Left</div>
    <div class="text-center">Text Center</div>
    <div class="text-right">Text Right</div>
    
  • 下划线重:decoration-[weight]

    <div class="underline decoration-2">Decoration 2</div>
    <div class="underline decoration-4">Decoration 4</div>
    <div class="underline decoration-8">Decoration 8</div>
    
  • 下划线风格:decoration-[type]

    <div class="underline decoration-double">Decoration Double</div>
    <div class="underline decoration-dotted">Decoration Dotted</div>
    <div class="underline decoration-dashed">Decoration Dashed</div>
    <div class="underline decoration-wavy">Decoration Wavy</div>
    
  • 装饰偏移量:underline-offset-[number]

    <div class="underline underline-offset-2">Offset 2</div>
    <div class="underline underline-offset-4">Offset 4</div>
    <div class="underline underline-offset-8">Offset 8</div>
    
  • 文本变换:

    <p class="normal-case">Normal Case</p>
    <p class="uppercase">uppercase</p>
    <p class="lowercase">LOWERCASE</p>
    <p class="capitalize">capitalize test</p>
    

4、宽度与高度

  • 宽度:w-[number]

    • number 取值 0~48
    <div class="bg-black text-white mb-2 w-6">Width 1.5rem</div>
    <div class="bg-black text-white mb-2 w-12">Width 3rem</div>
    <div class="bg-black text-white mb-2 w-24">Width 6rem</div>
    
  • 百分比:w-[number_1]/[number_2]

    <div class="bg-black text-white mb-2 w-1/4">Width 25%</div>
    <div class="bg-black text-white mb-2 w-1/3">Width 33%</div>
    <div class="bg-black text-white mb-2 w-1/2">Width 50%</div>
    
  • 视点宽度

    <div class="bg-black text-white w-screen">Width 100vw</div>
    
  • 100% 容器

    <div class="bg-black text-white w-full">Width 100%</div>
    
  • 自定义宽度

    <div class="bg-black text-white w-[300px]">Width 300px</div>
    
  • 最大宽度:max-w-[size]

    <div class="bg-black text-white mx-auto max-w-xs">
      Tailwind CSS is the only framework that I've
      seen scale on large teams. It’s easy to customize,
      adapts to any design, and the build size is tiny.
    </div>
    
  • 高度(大部分与宽度方法相同):h-[number]

    • number 取值 0~96
    <div class="flex items-end">
      <div class="bg-black text-white w-20 h-24">Height 24</div>
      <div class="bg-black text-white w-20 h-48">Height 48</div>
      <div class="bg-black text-white w-20 h-72">Height 72</div>
      <div class="bg-black text-white w-20 h-96">Height 96</div>
    </div>
    
  • 全屏高度

    <div class="bg-black text-white h-screen">Height 100vh</div>
    

5、布局与定位

  • 定位:相对定位与绝对定位

    <div class="relative w-1/2 h-12 bg-red-200">
      <p>Parent</p>
      <div class="absolute bottom-0 right-0 bg-red-700">
        <p>Child</p>
      </div>
    </div>
    
  • 左上角

    <div class="relative w-32 h-32 bg-red-200">
      <div class="absolute w-16 h-16 top-0 left-0 bg-red-700"></div>
    </div>
    
  • 右上角

    <div class="relative w-32 h-32 bg-red-200">
      <div class="absolute w-16 h-16 top-0 right-0 bg-red-700"></div>
    </div>
    
  • 左下角

    <div class="relative w-32 h-32 bg-red-200">
      <div class="absolute w-16 h-16 bottom-0 left-0 bg-red-700"></div>
    </div>
    
  • 右下角

    <div class="relative w-32 h-32 bg-red-200">
      <div class="absolute w-16 h-16 bottom-0 right-0 bg-red-700"></div>
    </div>
    
  • 顶边

    <div class="relative w-32 h-32 bg-red-200">
      <div class="absolute h-16 top-0 inset-x-0 bg-red-700"></div>
    </div>
    
  • 左边

    <div class="relative w-32 h-32 bg-red-200">
      <div class="absolute w-16 left-0 inset-y-0 bg-red-700"></div>
    </div>
    
  • 右边

    <div class="relative w-32 h-32 bg-red-200">
      <div class="absolute w-16 right-0 inset-y-0 bg-red-700"></div>
    </div>
    
  • 底边

    <div class="relative w-32 h-32 bg-red-200">
      <div class="absolute h-16 bottom-0 inset-x-0 bg-red-700"></div>
    </div>
    
  • 显示方式

    <div>
      Tailwind CSS is the only framework that 
      <span class="text-red-500 inline">(Inline)</span>
      I've seen scale on large teams.
      <span class="text-red-500 inline-block">(Inline-block)</span>
      It’s easy to customize, adapts to any design,
      <span class="text-red-500 block">(Block)</span>
      and the build size is tiny.
      <span class="text-red-500 hidden">(Hidden)</span>
    </div>
    
  • 层叠等级(Z 轴索引):z-[number/auto]

    <div class="relative h-24">
      <div class="absolute left-0 w-24 h-24 bg-red-100 z-40">1</div>
      <div class="absolute left-20 w-24 h-24 bg-red-200 z-30">2</div>
      <div class="absolute left-40 w-24 h-24 bg-red-500 z-20">3</div>
      <div class="absolute left-60 w-24 h-24 bg-red-700 z-10">4</div>
      <div class="absolute left-80 w-24 h-24 bg-red-900">5</div>
    </div>
    
  • 浮动:float-[left/right/none]

    <div class="h-24">
      <div class="w-24 h-24 bg-red-100 float-left">1</div>
      <div class="w-24 h-24 bg-red-200 inline-block">2</div>
    </div>
    

6、背景与阴影

  • 背景

    <div
      class="w-64 h-64 bg-cover bg-no-repeat bg-center"
      style="background-image: url('https://example.com/png');"
    ></div>
    
    • 大小

      bg-autobg-coverbg-contain
    • 重复

      bg-repeatbg-no-repeatbg-repeat-x
      bg-repeat-ybg-repeat-roundbg-repeat-space
    • 定位

      bg-centerbg-topbg-bottom
      bg-leftbg-left-topbg-left-bottom
      bg-rightbg-right-topbg-right-bottom
    • attachment

      bg-fixedbg-localbg-scroll
  • 渐变:bg-gradient-to-[direct] from-[color]-[shade] to-[color]-[shade]

    <div class="h-24 bg-gradient-to-r from-red-500 to-blue-500"></div>
    
  • 阴影

    <div class="w-96 shadow-2xl">
      Consectetur velit laboris tempor laboris qui consequat eu minim ipsum nulla culpa aliquip ad.
    </div>
    
    Tailwind Background ClassCSS Code
    shadow-smbox-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    shadowbox-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    shadow-mdbox-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    shadow-lgbox-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    shadow-xlbox-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1) 0 8px 10px -6px rgb(0 0 0 / 0.1);
    shadow-2xlbox-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
    shadow-innerbox-shadow: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);
    shadow-nonebox-shadow: 0 0 #0000;
  • 混合

    <div class="flex justify-center -space-x-24">
      <div class="mix-blend-multiply bg-red-500">
        Id ex deserunt velit excepteur deserunt tempor eu aliquip ipsum labore laboris.
      </div>
      <div class="mix-blend-multiply bg-blue-500">
        Adipisicing voluptate magna aute sunt consequat irure sint.
      </div>
    </div>
    

7、边框

  • 宽度:border(-[direct])-[width]

    • (-[direct]):取值为 t、l、r、b、x 或 y,分别对应上、左、右、下、左右或上下
    • width:取值为 0、2、4 或 8,分别对应 0px、2px、4px、8px
    <div class="w-96 m-5 p-5 border-2">
      Amet commodo nisi quis irure velit Lorem enim anim commodo sunt aliquip officia quis.
    </div>
    <div class="w-96 m-5 p-5 border-x-4">
      Amet commodo nisi quis irure velit Lorem enim anim commodo sunt aliquip officia quis.
    </div>
    <div class="w-96 m-5 p-5 border-y-8">
      Amet commodo nisi quis irure velit Lorem enim anim commodo sunt aliquip officia quis.
    </div>
    
  • 圆角:rounded(-[direct])(-[size])

    • (-[direct]):取值为 t、l、r、b、x 或 y,分别对应上、左、右、下、左右或上下
    • (-[size]):取值为 none、sm、md、lg、xl、2xl、3xl、full
    <div class="w-96 w-5 p-5 border-4 rounded-xl">
      Dolore deserunt sunt qui ut quis sunt anim do nostrud minim fugiat minim.
    </div>
    
  • 轮廓线:outline(-[width])

    • (-[width]):取值为 0、1、2、4、8
    <button class="m-5 outline outline-8">Click</button>
    

8、过滤器

  • 模糊:blur(-[size])

    • (-[size]):取值为 none、sm、【略】、md、lg、xl、2xl、3xl
    <div class="blur-sm">
      Do elit adipisicing cupidatat dolor excepteur nulla in incididunt.
    </div>
    
  • 亮度:brightness-[number]

    • numberfilter: brightness(number*0.1)
    <div class="h-16 bg-red-500 brightness-0">Brightness 0</div>
    <div class="h-16 bg-red-500 brightness-100">Brightness 100</div>
    <div class="h-16 bg-red-500 brightness-200">Brightness 200</div>
    
  • 对比度:contrast-[number]

    • numberfilter: contrast(number*0.1)
    <div class="h-16 bg-red-500 contrast-0">Contrast 0</div>
    <div class="h-16 bg-red-500 contrast-50">Contrast 50</div>
    <div class="h-16 bg-red-500 contrast-200">Contrast 200</div>
    
  • 灰度

    <div class="h-16 bg-red-500 grayscale">Grayscale</div>
    
  • 反色

    <div class="h-16 bg-red-500 invert">Invert</div>
    
  • 褐化

    <div class="h-16 bg-red-500 sepia">Sepia</div>
    
  • Hue rotate:hue-rotateo-[number]

    • number:取值为 0、15、30、60、90、180
    <div class="h-16 bg-red-500 hue-rotate-0">Hue Rotate 0</div>
    <div class="h-16 bg-red-500 hue-rotate-90">Hue Rotate 90</div>
    <div class="h-16 bg-red-500 hue-rotate-180">Hue Rotate 180</div>
    

9、 进阶应用

(1)交互

  • 悬停:hover:

    <button class="bg-black text-white rounded-lg m-5 p-5 hover:bg-blue-200 hover:text-black">Click</button>
    
  • 聚焦:focus:

    <button class="bg-black text-white rounded-lg m-5 p-5 focus:bg-blue-200 focus:text-black">Click</button>
    
  • 触发:active:

    <button class="bg-black text-white rounded-lg m-5 p-5 active:bg-blue-200 active:text-black">Click</button>
    
  • 设置内部元素样式

    <div class="group block max-w-xs mx-auto rounded-lg p-6 bg-white shadow-lg space-y-3 hover:bg-red-500">
      <h3 class="hover:text-white">Title</h3>
      <p class="group-hover:text-white">Laboris tempor ex nisi deserunt labore anim et do in officia sint laborum.</p>
    </div>
    
  • 伪类

    <ul>
      <li class="first:bg-red-500">Item 1</li>
      <li class="first:bg-red-500">Item 2</li>
      <li class="first:bg-red-500 even:bg-red-200 odd:bg-red-700">Item 3</li>
      <li class="first:bg-red-500 even:bg-red-200 odd:bg-red-700">Item 4</li>
      <li class="first:bg-red-500 even:bg-red-200 odd:bg-red-700">Item 5</li>
    </ul>
    
  • 外观

    • 一般用于重置浏览器或操作系统默认的样式外观
    <select class="border-4 border-red-500">
      <option value="1">True</option>
      <option value="0">False</option>
    </select>
    <select class="border-4 border-green-500 appearance-none">
      <option value="1">True</option>
      <option value="0">False</option>
    </select>
    
  • 游标:cursor-[type]

    • type 常见取值为

      autodefaultpointerwaittextmovehelp
      not-allowednonecontext-menuprogresscellcrosshairvertical-text
    <div class="w-36 h-36 bg-red-500 cursor-pointer"></div>
    
  • 选中

    <div class="select-none">Select None</div>
    <div class="select-text">Select Text</div>
    <div class="select-all">Select All</div>
    <div class="select-auto">Select Auto</div>
    
  • 平滑滚动示例

    <!DOCTYPE html>
    <html lang="en" class="scroll-smooth">
      <head>
        <!-- ... -->
        <script src="https://cdn.tailwindcss.com/"></script>
      </head>
      <body>
        <a href="#bottom" class="block m-6 border-4 text-center">Go to Bottom</a>
        <div class="h-[1000px] bg-black"></div>
        <div id="bottom" class="h-4 text-center">Bottom</div>
      </body>
    </html>
    

(2)断点类与媒体查询

  1. 窗口宽度实时监听

    <body>
      <h1></h1>
      <script>
        function showBrowserWidth() {
          const width = window.innerWidth
          document.querySelector('h1').innerText = `Width: ${width}`
        }
        window.onload = showBrowserWidth
        window.onresize = showBrowserWidth
      </script>
    </body>
    
  2. 修改 h1 标签样式,设置默认背景颜色

    <body class="bg-black">
      <h1 class="text-white text-4xl"></h1>
      <script>
        function showBrowserWidth() {
          const width = window.innerWidth
          document.querySelector('h1').innerText = `Width: ${width}`
        }
        window.onload = showBrowserWidth
        window.onresize = showBrowserWidth
      </script>
    </body>
    
  3. body 标签中,根据窗口宽度设置背景颜色变化

    <body class="bg-black sm:bg-red-700">
      <!-- ... -->
    </body>
    
    sizemin-width
    sm640px
    md768px
    lg1024px
    xl1280px
    2xl1536px

(3)分栏

  • 基本列:columns-[number/type]

    • number:取值 1~12
    • type:取值 auto、3xs、2xs、xs、sm、md、lg、xl、2xl、3xl、4xl、5xl、6xl、7xl
    <div class="columns-3">
      <div class="w-full m-2 border-4 border-red-500">Proident ipsum consequat dolor deserunt.</div>
      <div class="w-full m-2 border-4 border-yellow-500">Proident ipsum consequat dolor deserunt.</div>
      <div class="w-full m-2 border-4 border-green-500">Proident ipsum consequat dolor deserunt.</div>
      <div class="w-full m-2 border-4 border-blue-500">Proident ipsum consequat dolor deserunt.</div>
    </div>
    
  • 纵横比:aspect-[type]

    <div class="columns-1">
      <div class="w-60 m-2 border-4 border-red-500 aspect-square">Proident ipsum consequat dolor deserunt.</div>
      <div class="w-60 m-2 border-4 border-blue-500 aspect-video">Proident ipsum consequat dolor deserunt.</div>
    </div>
    

(4)Flexbox

  • Flex 与对齐

    1. 创建一个 Flexbox

      <div class="flex w-full h-72 bg-black">
        <div class="p-10 border border-red-500 bg-red-200">1</div>
        <div class="p-10 border border-yellow-500 bg-yellow-200">2</div>
        <div class="p-10 border border-green-500 bg-green-200">3</div>
        <div class="p-10 border border-blue-500 bg-blue-200">4</div>
      </div>
      
    2. 设置每项的对齐方向:items-[type]

      <div class="flex w-full h-72 bg-black items-center">
        <!-- ... -->
      </div>
      
    3. 设置每项的对齐方式:justify-[type]

      <div class="flex w-full h-72 bg-black items-center justify-around">
        <!-- ... -->
      </div>
      
    4. 设置换行,使某一项超出窗口:flex-wrap

      <div class="flex flex-wrap w-full h-72 bg-black items-center justify-around">
        <div class="p-10 border border-red-500 bg-red-200">1</div>
        <div class="p-10 border border-yellow-500 bg-yellow-200">2</div>
        <div class="p-10 w-[300px] border border-green-500 bg-green-200">3</div>
        <div class="p-10 border border-blue-500 bg-blue-200">4</div>
      </div>
      
  • 列、间隙、顺序

    1. 创建一个 Flexbox,设置为纵向排列

      <div class="flex flex-col w-72 bg-black">
        <div class="p-10 border border-red-500 bg-red-200">1</div>
        <div class="p-10 border border-yellow-500 bg-yellow-200">2</div>
        <div class="p-10 border border-green-500 bg-green-200">3</div>
        <div class="p-10 border border-blue-500 bg-blue-200">4</div>
      </div>
      
    2. 设置间隙:gap-[number]number * 0.25rem)

      <div class="flex flex-col w-72 bg-black gap-4">
        <!-- ... -->
      </div>
      
    3. 调整顺序:order-[index]

      <div class="flex flex-col w-72 bg-black gap-4">
        <div class="p-10 border border-red-500 bg-red-200 order-2">1</div>
        <div class="p-10 border border-yellow-500 bg-yellow-200 order-1">2</div>
        <div class="p-10 border border-green-500 bg-green-200 order-4">3</div>
        <div class="p-10 border border-blue-500 bg-blue-200 order-3">4</div>
      </div>
      
  • 放大与缩小

    <div class="flex w-full bg-black">
      <div class="p-10 w-64 border border-red-500 bg-red-200">1</div>
      <div class="flex-none p-10 w-64 border border-yellow-500 bg-yellow-200">2</div>
      <div class="p-10 w-64 border border-green-500 bg-green-200">3</div>
      <div class="p-10 border border-blue-500 bg-blue-200">4</div>
      <div class="p-10 w-64 border border-gray-500 bg-gray-200">5</div>
    </div>
    

(5)Grid

  • 模板列:grid-cols-[number/none]

    • number:取值为 1~12
    • 该语句等同于:grid-template-columns: repeat(number, minmax(0, 1fr));
    <div class="grid grid-cols-3 gap-2">
      <div class="p-10 border-4 border-red-200 bg-blue-200">Item 1</div>
      <div class="p-10 border-4 border-red-200 bg-blue-200">Item 2</div>
      <div class="p-10 border-4 border-red-200 bg-blue-200">Item 3</div>
      <div class="p-10 border-4 border-red-200 bg-blue-200">Item 4</div>
      <div class="p-10 border-4 border-red-200 bg-blue-200">Item 5</div>
      <div class="p-10 border-4 border-red-200 bg-blue-200">Item 6</div>
      <div class="p-10 border-4 border-red-200 bg-blue-200">Item 7</div>
      <div class="p-10 border-4 border-red-200 bg-blue-200">Item 8</div>
      <div class="p-10 border-4 border-red-200 bg-blue-200">Item 9</div>
    </div>
    
  • 模板行:grid-rows-[number/none]

    • number:取值为 1~6
    • 该语句等同于:grid-template-rows: repeat(number, minmax(0, 1fr));
    <div class="grid grid-cols-2 gap-2 grid-rows-4 bg-gray-200">
      <!-- ... -->
    </div>
    
  • 跨行/列:[row/col]-span-[number]

    • row-span-[number]:跨 number
    • col-span-[number]:跨 number
    <div class="grid grid-cols-3 gap-2">
      <div class="row-span-3 p-10 border-4 border-red-200 bg-blue-200">Item 1</div>
      <div class="md:col-span-2 p-10 border-4 border-red-200 bg-blue-200">Item 2</div>
      <!-- ... -->
    </div>
    

(6)过渡与变换

初始按钮:

<button class="m-4 px-8 py-4 text-white bg-blue-200 rounded hover:bg-blue-700">Click</button>
  • 过渡

    • transition-[type]:过渡类型,type 取值为 none、all、colors、opacity、shadow、transform
    • duration-[ms]:过渡时长,ms 取值为 75、100、150、200、300、500、700、1000
    • ease-[type]:过渡效果,type 取值为 linear、in、out、in-out
    • delay-[ms]:延时时长,ms 取值为 75、100、150、200、300、500、700、1000
    <button class="m-4 px-8 py-4 text-white bg-blue-200 rounded hover:bg-blue-700 transition-colors duration-700 ease-in delay-100">Click</button>
    
  • 变换

    • scale(-[axis])-[magnification]:缩放,axis 表示参照轴,取值为 x 或 y;magnification 表示缩放倍率,为 number%
    • rotate-[degree]:旋转,degree 表示旋转角度
    • translate-[axis]-[distance]:位移,axis 表示参照轴,取值为 x 或 y;distance 表示位移距离,整数为 number * 0.25rem,分数为占比,full 为 100%,px 为 1px
    • skew-[direct]-[degree]:倾斜,axis 表示参照轴,取值为 x 或 y;degree 表示倾斜角度
    <button class="m-4 px-8 py-4 text-white bg-blue-200 rounded hover:scale-50 hover:rotate-12 hover:translate-x-2 hover:skew-x-12 duration-700">Click</button>
    

(7)动画类与关键帧

  • animate-[property]property 取值如下:

    • none:animation: none;

    • spin:旋转

      animate: spin 1s linear infinite;
      @keyframes spin {
          from {
              transform: rotate(0deg);
          }
          to {
              transform: rotate(360deg);
          }
      }
      
    • ping:扩散

      animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
      @keyframes ping {
          75%, 100% {
              transform: scale(2);
              opacity: 0;
          }
      }
      
    • pulse:闪烁

      animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
      @keyframes pulse {
          0%, 100% {
              opacity: 1;
          }
          50% {
              opacity: .5;
          }
      }
      
    • bounce:弹跳

      animation: bounce 1s infinite;
      @keyframes bounce {
          0%, 100% {
              transform: translateY(-25%);
              animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
          }
          50% {
              transform: translateY(0);
              animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
          }
      }
      
    <div class="w-64 h-64 bg-red-200 rounded-full relative animate-ping">
      <div class="w-32 h-2 bg-gradient-to-r from-red-500 to-yellow-500 absolute right-0 top-1/2"></div>
    </div>
    
  • 自定义动画与关键帧

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <!-- ... -->
        <script>
          tailwind.config = {
            theme: {
              extend: {
                animation: {
                  'slow-spin': 'spin 3s linear infinite',
                  'custom': 'custom 1s linear infinite'
                },
                keyframes: {
                  'custom': {
                    '0%': {
                      transform: 'rotate(0deg)'
                    },
                    '90%, 100%': {
                      transform: 'rotate(360deg)'
                    }
                  }
                }
              }
            }
          }
        </script>
      </head>
      <body>
        <div class="w-64 h-64 bg-red-200 rounded-full relative animate-custom">
          <div class="w-32 h-2 bg-gradient-to-r from-red-500 to-yellow-500 absolute right-0 top-1/2"></div>
        </div>
      </body>
    </html>
    

(8)配置与客制化

  • head 标签中的 script 标签中写入配置

  • 配置格式:

    <script>
      tailwind.config = {
        theme: {
          extend: {
            'property-1': {
              'key-1-1': 'value-1-1',
            },
            'property-2': {
              'key-2-1': 'value-2-1',
            },
            // ...
          }
        }
      }
    </script>
    

(9)夜间模式

  • 配置夜间模式样式:dark:

    <div class="w-64 h-64 bg-white dark:bg-gray-900"></div>
    
  • 是否使用夜间模式,默认根据操作系统

  • 使用 Javascript 控制夜间模式

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <!-- ... -->
        <script>
          tailwind.config = {
            darkMode: "class",
          };
        </script>
        <style>
          .toggle-checkbox:checked {
            right: 0;
            border-color: #68d391;
          }
          .toggle-checkbox:checked + .toggle-label {
            background: #68d391;
          }
        </style>
      </head>
      <body>
        <div
          class="container mx-auto mt-10 bg-white dark:bg-slate-900 rounded-xl px-6 py-8 shadow-xl"
        >
          <h3 class="text-slate-900 dark:text-white font-medium tracking-tight">
            Title
          </h3>
          <p class="text-slate-500 dark:text-slate-400 mt-2 text-sm">
            Irure dolor ut excepteur ea cupidatat dolor dolore consectetur sit
            voluptate qui et deserunt.
          </p>
        </div>
        <div
          class="relative inline-block w-10 mr-2 mt-6 ml-6 align-middle select-none transition duration-200 ease-in"
        >
          <input
            type="checkbox"
            name="toggle"
            id="toggle"
            class="toggle-checkbox absolute block w-6 h-6 rounded-full bg-white border-4 dark:bg-gray-700 appearance-none cursor-pointer"
          />
          <label
            for="toggle"
            class="toggle-label block overflow-hidden h-6 rounded-full bg-gray-300 cursor-pointer"
          ></label>
        </div>
        <script>
          document.getElementById("toggle").addEventListener("change", function () {
            if (this.checked) {
              document.documentElement.classList.add("dark");
            } else {
              document.documentElement.classList.remove("dark");
            }
          });
        </script>
      </body>
    </html>
    

(10)分组

  • 子选择:group[/name],如:

    <body>
      <div class="size-36 bg-black group/box">
        <div class="size-24 bg-gray-500 group-hover/box:bg-red-500"></div>
      </div>
    </body>
    
  • 兄弟选择:peer[/name],如:

    <body>
      <div class="size-36 bg-black mb-4 peer/box"></div>
      <div class="size-36 bg-gray-500 peer-hover/box:bg-red-500"></div>
    </body>
    
    • 注意,兄弟选择仅支持对被命名的元素后面的元素选择

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/892645.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

极化基变化后的散射矩阵

极化基只旋转一次 重点&#xff1a;发射和接收的电磁波可以理解为&#xff0c;在极化基上的坐标&#xff0c;或者就是琼斯矢量&#xff1b; 其中极化基坐标的理解方式在想发射的时候好理解&#xff0c;回波由于多了个共轭&#xff0c;就想其接收到的不是坐标&#xff0c;而是琼…

Power BI:链接数据库与动态数据展示案例

一、案例背景 在数据驱动的时代&#xff0c;如何高效、直观地展示和分析数据成为了企业决策和个人洞察的关键。Power BI作为一款强大的商业智能工具&#xff0c;凭借其强大的数据连接能力、丰富的可视化选项以及交互性和动态性&#xff0c;成为了众多企业和个人的首选。本文将…

unity学习笔记-Text mesh Pro

Text mesh Pro组件 组件使用的大致流程细节导入之后字体没有显示可能一 可能二 注意事项 好久没更了…最近在学习使用别人的框架进行开发&#xff0c;坑也不少&#xff0c;不过学习到了很多设计思维。 言归正传。忘了是什么是时候的版本开始&#xff0c;unity多了这个组件&…

nextjs项目中,使用postgres的完整案例

目的 通过此案例&#xff0c;可以简单快速的过一下数据库的操作&#xff0c;熟悉app-router这种模式下&#xff0c;client component和server component的两种组件中基本的接口使用。 技术栈 nextjs14.2.* app-routervercel/postgres0.10.*typescript5 重要事情说三遍1 ap…

解决visio2021与本地家庭和学生版office21不兼容问题

原因分析 office 分为 MSI(windows Installer)和C2R(即点即用版本) 两个版本。 下载对应版本 可以看这个B站哥哥的资源&#xff1a;https://www.bilibili.com/read/cv17513800/ &#xff0c;选择标准离线版本安装

[单master节点k8s部署]37.微服务(一)springCloud 微服务

微服务架构的一个重要特点是&#xff0c;它与开发中使用的具体编程语言或技术栈无关。每个微服务都可以使用最适合其功能需求的语言或技术来实现。例如&#xff0c;一个微服务可以用Java编写&#xff0c;另一个微服务可以用Python、Go、Node.js等编写。微服务架构允许这种灵活性…

基于Arduino做的“鱿鱼游戏”BOSS面具,支持动作检测

这是一个结合了3D打印、舵机、PIR传感器和DFPlayer MP3模块的DIY项目&#xff0c;旨在制作一个带有动画眼睛的"鱿鱼游戏"老板面具。当检测到动作时&#xff0c;面具的眼睛会移动并播放声音&#xff0c;非常适合万圣节使用。 这个项目是一个很好的起点&#xff0c;特…

又一支付机构“经营异常”——易极付

近日&#xff0c;支付行业再次传出风波&#xff0c;重庆易极付科技有限公司&#xff08;简称“易极付”&#xff09;因“失联”问题被重庆两江新区市场监督管理局列入了经营异常名录。据天眼查平台显示&#xff0c;这一决定是基于“通过登记的住所或者经营场所无法联系”到该公…

【CSS in Depth 2 精译_050】7.3 CSS 响应式设计中的流式布局原则(Fluid layout)

当前内容所在位置&#xff08;可进入专栏查看其他译好的章节内容&#xff09; 【第七章 响应式设计】&#xff08;概述&#xff09; 7.1 移动端优先设计原则&#xff08;上篇&#xff09; 7.1.1 创建移动端菜单&#xff08;下篇&#xff09;7.1.2 给视口添加 meta 标签&#xf…

Linux Debian12基于ImageMagick图像处理工具编写shell脚本用于常见图片png、jpg、jpeg、tiff格式批量转webp格式

在Linux系统中&#xff0c;使用ImageMagick可以图片格式转换&#xff0c;其中最常用的是通过命令行工具进行。 ImageMagick是一个非常强大的图像处理工具集&#xff0c;它包含了许多用于图像转换的命令。 一、安装ImageMagick&#xff08;如果尚未安装&#xff09;&#xff1…

Python | Leetcode Python题解之第486题预测赢家

题目&#xff1a; 题解&#xff1a; class Solution:def PredictTheWinner(self, nums: List[int]) -> bool:length len(nums)dp [0] * lengthfor i, num in enumerate(nums):dp[i] numfor i in range(length - 2, -1, -1):for j in range(i 1, length):dp[j] max(num…

力扣21~30题

21题&#xff08;简单&#xff09;&#xff1a; 分析&#xff1a; 按要求照做就好了&#xff0c;这种链表基本操作适合用c写&#xff0c;python用起来真的很奇怪 python代码&#xff1a; # Definition for singly-linked list. # class ListNode: # def __init__(self, v…

leetcode30:串联所有单词的字串

给定一个字符串 s 和一个字符串数组 words。 words 中所有字符串 长度相同。 s 中的 串联子串 是指一个包含 words 中所有字符串以任意顺序排列连接起来的子串。 例如&#xff0c;如果 words ["ab","cd","ef"]&#xff0c; 那么 "abcdef…

NetSarang Xshell v8.0060 Linux终端管理器个人免费版

NetSarang Xshell 官方个人完全免费中文版&#xff0c;Xshell特别版&#xff0c;Xshell 个人完全免费&#xff0c;Xshell 是一款最好用的Linux远程连接工具&#xff0c;免费SSH客户端、主机服务器远程管理客户端 。Xshell&#xff0c;轻松管理远程服务器&#xff0c;会话管理器…

《人工智能:CSDN 平台上的璀璨之星》

一、CSDN 上的 AI 热门话题 GPT-3 作为 CSDN 上的热门话题&#xff0c;其应用极为广泛。GPT-3 是 OpenAI 开发的一种基于 Transformer 架构的大规模预训练语言模型&#xff0c;拥有惊人的 1750 亿个参数。它具有多任务处理能力&#xff0c;能够执行多种自然语言处理任务&#x…

基于KNN算法的指纹定位系统(MATLAB,平面,四个锚点)

文章目录 指纹定位指纹定位技术简介基本原理位置估算公式1. 最近邻居算法&#xff08;KNN&#xff09;2. 加权最近邻居算法&#xff08;W-KNN&#xff09;3. 最小二乘法&#xff08;LS&#xff09; 最终位置 P P P通过求解下面的方程获得&#xff1a;应用场景优缺点优点缺点 总…

Python 工具库每日推荐 【pyspider 】

文章目录 引言网络爬虫的重要性今日推荐:pyspider 网络爬虫框架主要功能:使用场景:安装与配置快速上手示例代码代码解释实际应用案例案例:爬取新闻网站的文章案例分析高级特性使用代理处理 JavaScript 渲染的页面扩展阅读与资源优缺点分析优点:缺点:总结【 已更新完 Type…

《深度学习》OpenCV 风格迁移、DNN模块 案例解析及实现

目录 一、风格迁移 1、什么是风格迁移 2、步骤 1&#xff09;训练 2&#xff09;迁移 二、DNN模块 1、什么是DNN模块 2、DNN模块特点 1&#xff09;轻量 2&#xff09;外部依赖性低 3&#xff09;方便 4&#xff09;集成 5&#xff09;通用性 3、流程图 4、图像…

玛泽的故事中英文Big Muzzy台词本电子版PDF

《Big Muzzy》玛泽的故事&#xff0c;中英文都有&#xff0c;是BBC制作的&#xff0c;专为英语初学者设计的外语课程。它是教学动画里最有趣的一部&#xff01;风靡全球&#xff0c;上百个国家引进&#xff0c;深受小朋友的喜爱。《Big Muzzy》用动画的形式&#xff0c;讲述了M…

第九课:Python学习之函数基础

函数基础 目标 函数的快速体验函数的基本使用函数的参数函数的返回值函数的嵌套调用在模块中定义函数 01. 函数的快速体验 1.1 快速体验 所谓函数&#xff0c;就是把 具有独立功能的代码块 组织为一个小模块&#xff0c;在需要的时候 调用函数的使用包含两个步骤&#xff…