AVt天堂网 手机版,亚洲va久久久噜噜噜久久4399,天天综合亚洲色在线精品,亚洲一级Av无码毛片久久精品

當(dāng)前位置:首頁(yè) > 科技  > 軟件

為什么Tailwindcss在開(kāi)發(fā)者中如此受歡迎?揭秘背后的原因!

來(lái)源: 責(zé)編: 時(shí)間:2024-09-10 09:50:38 89觀看
導(dǎo)讀1.邂逅 tailwindcss我們平時(shí)寫(xiě) css 樣式是這樣的:<template> <div class="zhifou"> <p>好好學(xué)習(xí)</p> <p>天天向上</p> </div></template><script setup></script><style lang="scss" scoped>.zhifo

1.邂逅 tailwindcss

我們平時(shí)寫(xiě) css 樣式是這樣的:LYT28資訊網(wǎng)——每日最新資訊28at.com

<template>  <div class="zhifou">    <p>好好學(xué)習(xí)</p>    <p>天天向上</p>  </div></template><script setup></script><style lang="scss" scoped>.zhifou {  margin: auto;  width: 600px;  height: 300px;  background-color: blue;  font-size: 20px;}</style>

后來(lái)隨著前端技術(shù)的發(fā)展,原子化 CSS 出現(xiàn)了。原子化 CSS 是一種 CSS 框架。LYT28資訊網(wǎng)——每日最新資訊28at.com

在原子化 CSS 中,CSS 組件被拆分為更小的部分,這些部分可以獨(dú)立地編輯、測(cè)試和重用。這些原子通常是單個(gè)像素或極其微小的變化,例如顏色、大小、位置等。LYT28資訊網(wǎng)——每日最新資訊28at.com

原子化 CSS 有助于減少代碼量,提高代碼的可維護(hù)性和可重用性。LYT28資訊網(wǎng)——每日最新資訊28at.com

原子化 CSS 寫(xiě)法:LYT28資訊網(wǎng)——每日最新資訊28at.com

<div class="w-10 h-10 bg-red-100 text-10">    <p>好好學(xué)習(xí)</p>    <p>天天向上</p>  </div>

原子化 CSS 框架更像是一個(gè)已經(jīng)封裝好的 CSS 工具類(lèi)。LYT28資訊網(wǎng)——每日最新資訊28at.com

例如:我們?cè)陬?lèi)選擇器中寫(xiě)了 w-[10px],原子化 CSS 框架經(jīng)過(guò)掃描,將 w-[10px] 掃描成LYT28資訊網(wǎng)——每日最新資訊28at.com

width:10px;

也就是說(shuō),我們只要按照這個(gè)框架的要求去任意組合,框架最后一掃描,就能生成我們想要的 CSS 樣式。這樣會(huì)大大減少代碼量,提高工作效率。LYT28資訊網(wǎng)——每日最新資訊28at.com

而本文介紹的 tailwindcss 就是市面上非常熱門(mén)的原子化 CSS 框架。LYT28資訊網(wǎng)——每日最新資訊28at.com

tailwindcss 中文網(wǎng)LYT28資訊網(wǎng)——每日最新資訊28at.com

https://www.tailwindcss.cn/

圖片圖片LYT28資訊網(wǎng)——每日最新資訊28at.com

4. tailwindcss 常用方法

4.1 設(shè)置寬高

1.w-[ ],h-[ ] 設(shè)置任意寬高

<template>  <div>    <div class="bg-blue-600 w-[200px] h-[100px]">      <p>好好學(xué)習(xí)</p>      <p>天天向上</p>    </div>    <div class="bg-red-600 w-[20rem] h-[10rem]">      <p>好好學(xué)習(xí)</p>      <p>天天向上</p>    </div>  </div></template><script setup></script><style lang="scss" scoped></style>

圖片圖片LYT28資訊網(wǎng)——每日最新資訊28at.com

4.7 定位

  • relative 表示 position: relative;
  • absolute 表示 position: absolute;
  • fiexed 表示 position: fiexed;
  • z-1 表示 z-index:1;

數(shù)值:1 表示 4pxLYT28資訊網(wǎng)——每日最新資訊28at.com

  • top-1 表示 top: 4px;
  • left-2 表示 left: 8px;
  • right-10 表示 right: 40px;
  • bottom-3 表示 bottom: 12px;

任意值:LYT28資訊網(wǎng)——每日最新資訊28at.com

  • top-[5px]
  • left-[10rem]
  • right-[20px]
  • bottom-[100px]

例:LYT28資訊網(wǎng)——每日最新資訊28at.com

<div  class="bg-blue-600 w-[300px] h-[300px] hover:bg-red-300 fixed bottom-[20px] left-[100px]">  <p class="font-bold text-yellow-400">好好學(xué)習(xí)</p>  <p>天天向上</p></div>

圖片圖片LYT28資訊網(wǎng)——每日最新資訊28at.com

4.8 flex 布局

  • flex 表示 display: flex;
  • flex-row 表示 flex-direction: row;
  • flex-col 表示 flex-direction: column;
  • justify-center 表示 justify-content: center;
  • items-center 表示 align-items: center;
  • flex-wrap 表示換行
  • flex-nowrap 表示不換行
  • flex-1 表示 flex:1;

例:LYT28資訊網(wǎng)——每日最新資訊28at.com

<div  class="bg-blue-600 w-[300px] h-[300px] flex flex-row justify-center items-center ">  <p class="bg-yellow-400 w-[100px] h-[100px] text-white-400">好好學(xué)習(xí)</p>  <p class="bg-red-400 w-[100px] h-[100px] text-white-400">天天向上</p></div>

圖片圖片LYT28資訊網(wǎng)——每日最新資訊28at.com

4.9 樣式復(fù)用

下面的例子中 p 標(biāo)簽有重復(fù)的樣式LYT28資訊網(wǎng)——每日最新資訊28at.com

<div  class="bg-blue-600 w-[300px] h-[300px] flex flex-row justify-center items-center flex-wrap">  <p class="bg-red-400 w-[100px] h-[100px] text-white text-[20px]">好好學(xué)習(xí)</p>  <p class="bg-yellow-400 w-[100px] h-[100px] text-white text-[20px]">天天向上</p></div>

如果遇到重復(fù)的樣式,我們可以借助 @layer 和 @apply 指令定義全局復(fù)用的樣式:LYT28資訊網(wǎng)——每日最新資訊28at.com

1.在 TailwindCSS 的樣式文件中定義復(fù)用樣式LYT28資訊網(wǎng)——每日最新資訊28at.com

圖片圖片LYT28資訊網(wǎng)——每日最新資訊28at.com

@layer components {  .title {    @apply w-[100px] h-[100px] text-white text-[20px];  }}

2.在類(lèi)選擇器中使用復(fù)用類(lèi)名LYT28資訊網(wǎng)——每日最新資訊28at.com

<p class="title">好好學(xué)習(xí)</p><p class="title">天天向上</p>


LYT28資訊網(wǎng)——每日最新資訊28at.com

本文鏈接:http://www.tebozhan.com/showinfo-26-112771-0.html為什么Tailwindcss在開(kāi)發(fā)者中如此受歡迎?揭秘背后的原因!

聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。郵件:2376512515@qq.com

上一篇: 2024年了,為什么 CSS 預(yù)處理器依然火爆?

下一篇: 如何利用CSS實(shí)現(xiàn)三角形、扇形、聊天氣泡框

標(biāo)簽:
  • 熱門(mén)焦點(diǎn)
Top