CSS加載器或旋轉器示例
這是一個純CSS實現的輕量級加載動畫,1. 使用HTML創建一個div容器;2. 通過CSS設置圓形邊框並僅對頂部著色;3. 利用@keyframes動畫持續旋轉元素;4. 可自定義大小、速度和顏色;5. 通過Flex佈局居中顯示;6. 結合JavaScript動態控制顯示與隱藏,適用於表單提交、數據加載等場景,完整且無需外部依賴。
Here's a simple and practical CSS loader (spinner) example you can use in your web projects. It's lightweight, pure CSS, and easy to customize.

? Simple CSS Spinner (Loader)
This spinner is great for showing loading states while content loads (eg, API calls, page transitions).
✅ HTML
<div class="loader"></div>
✅ CSS
.loader { width: 40px; height: 40px; border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; animation: spin 1s linear infinite; margin: 50px auto; /* Center it */ } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
? How It Works
- The spinner uses a circular border with only the top colored — this creates the "spinning" effect.
-
animation: spin 1s linear infinite
rotates the element continuously. - You can change:
- Size: adjust
width
/height
- Speed: change
1s
to faster (0.5s
) or slower - Colors: modify
border
andborder-top
values
- Size: adjust
?️ Optional: Centering the Loader on Screen
To center it vertically and horizontally:

body { display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; } .loader { width: 40px; height: 40px; border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; animation: spin 1s linear infinite; }
? Use Cases
- Show during form submission
- While fetching data from an API
- On page navigation (single-page apps)
- Inside buttons (eg, "Loading...")
You can wrap it in a container and hide it when not needed:
.loader-container { display: none; /* Show dynamically with JS */ } .loader-container.active { display: block; }
That's it — a clean, modern spinner with no JavaScript or external libraries needed. Basically just a few lines of CSS.

以上是CSS加載器或旋轉器示例的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undress AI Tool
免費脫衣圖片

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Stock Market GPT
人工智慧支援投資研究,做出更明智的決策

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

使用HTML和CSS可創建無需JavaScript的下拉菜單。 2.通過:hover偽類觸發子菜單顯示。 3.利用嵌套列表構建結構,CSS設置隱藏與懸浮顯示效果。 4.可添加過渡動畫提升視覺體驗。

Thepointer-eventspropertyinCSScontrolswhetheranelementcanbethetargetofpointerevents.1.Usepointer-events:nonetodisableinteractionslikeclicksorhoverswhilekeepingtheelementvisuallyvisible.2.Applyittooverlaystoallowclick-throughbehaviortounderlyingelemen

useobject-fitormax-widthwithheight:自動置換式; object-fitControlshowimagesfillcontainersfillcontainerswhilepreservingaspectratios,andmax-width:100%;高度;高度:autoEsoensuresResresresResresRessersRessiveScalingScalingWithOutStertracterging。

USETHEBOX-SHADOWPROPERTYTOADDDROPSHADOWS.DEFINEHORIZONTALANDVERTICALESTESETSETSETSETSETSETSETSETSETSETSETSETSETSETSETSETSETSETESTESTESTESTESTESTEMENG:MMULTIPLESHADOWSARECOMMA-SEPARAWS.MEULTIPLESHADOWSARECOMMA-SEPARATED.EXAMPL

thecssfilterpropertyallowseasyagestylinglingwisslikeblur,亮度和格雷斯卡爾(Grayscale.UseFilter):濾波器函數(值)onimagesorbackgroundImages.commonfunctionsIncludeBlurblur(px),亮度(brightness),亮度(%),偏見(%),損壞(%),sancale(%),飽和度(%)

要添加CSS漸變背景,使用background或background-image屬性配合linear-gradient()、radial-gradient()等函數即可;首先選擇漸變類型,設置方向與顏色,並可通過顏色停靠點、形狀、大小等參數精細控制,例如linear-gradient(toright,#ff7e5f,#feb47b)創建從左到右的線性漸變,radial-gradient(circle,#ff9a9e,#fecfef)創建圓形徑向漸變,還可通過repeating-linear-gr

使用border-radius:50%將等寬高的圖像變為圓形,結合object-fit和aspect-ratio確保形狀和裁剪,可添加邊框、陰影等樣式增強視覺效果。

使用gap、row-gap或column-gap屬性可在CSSGrid佈局中創建網格項之間的間距,gap是設置行列間距的簡寫屬性,可接受一個或兩個長度值,row-gap和column-gap則分別單獨控制行與列的間距,支持px、rem、%等單位。
