CSS教程,用於創建加載旋轉器和動畫
創建CSS加載旋轉器的方法有三種:1. 使用邊框的基本旋轉器,通過HTML和CSS實現簡單動畫;2. 使用多個點的自定義旋轉器,通過不同延遲時間實現跳動效果;3. 在按鈕中添加旋轉器,通過JavaScript切換類來顯示加載狀態。每種方法都強調了設計細節如顏色、大小、可訪問性和性能優化的重要性,以提升用戶體驗。
Creating loading spinners with CSS is a straightforward way to enhance user experience while content loads. You don't need JavaScript for simple animations — just HTML and CSS. Below are practical methods to build basic and customizable spinners.

Basic Spinner Using Borders
One of the simplest ways to create a spinner is by using a bordered element and rotating it with CSS animation.

HTML:
<div class="spinner"></div>
CSS:

.spinner { width: 40px; height: 40px; border: 4px solid #ccc; border-top-color: #333; border-radius: 50%; animation: spin 1s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } }
- The
border
creates the ring shape. -
border-top-color
gives the "loading" effect with a contrasting color. - The
spin
keyframe rotates the element infinitely.
This method works well for small, subtle loaders.
Custom Spinner with Multiple Dots
If you want something more visual than a rotating circle, consider animating multiple dots that appear one after another.
HTML:
<div class="dot-spinner"> <div class="dot"></div> <div class="dot"></div> <div class="dot"></div> </div>
CSS:
.dot-spinner { display: flex; gap: 5px; } .dot { width: 8px; height: 8px; background-color: #333; border-radius: 50%; animation: bounce 1.2s infinite ease-in-out; } .dot:nth-child(1) { animation-delay: -0.32s; } .dot:nth-child(2) { animation-delay: -0.16s; } @keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }
- Each dot scales in and out at slightly different times.
- This staggered animation gives a pulsing or bouncing effect.
- You can change the number of dots or adjust timing for different styles.
This type of spinner is great for modern UIs where subtle motion adds personality.
Adding Animation to Buttons
Sometimes you want to show a spinner inside a button when an action is processing.
HTML:
<button class="loading-btn"> <span class="btn-text">Submit</span> <span class="spinner"></span> </button>
CSS (partial):
.loading-btn .spinner { display: none; width: 16px; height: 16px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; margin-left: 8px; } .loading-btn.loading .spinner { display: inline-block; } .loading-btn.loading .btn-text { opacity: 0; }
- When the button has a
loading
class, the spinner appears and the text fades out. - You'd toggle the class using JavaScript when triggering an async action.
This approach keeps your interface responsive and gives feedback during actions like form submission.
Tips for Customization
Here are some quick tips to make your spinners work better:
- Use semantic colors : Match the spinner color to your theme or brand.
- Keep it small : Spinners shouldn't dominate the screen unless necessary.
- Consider accessibility : Add ARIA attributes if needed (
aria-busy
,role="status"
). - Optimize performance : Avoid overcomplicated animations that may slow down rendering.
You can mix these techniques or layer them depending on your project's needs.
That's basically how you create and customize spinners with just CSS. It's not complicated, but getting the details right makes a difference in how smooth and professional your interface feels.
以上是CSS教程,用於創建加載旋轉器和動畫的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undress AI Tool
免費脫衣圖片

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

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

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

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

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

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

Dreamweaver CS6
視覺化網頁開發工具

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

Autoprefixer是一個根據目標瀏覽器範圍自動為CSS屬性添加廠商前綴的工具。 1.它解決了手動維護前綴易出錯的問題;2.通過PostCSS插件形式工作,解析CSS、分析需加前綴的屬性、依配置生成代碼;3.使用步驟包括安裝插件、設置browserslist、在構建流程中啟用;4.注意事項有不手動加前綴、保持配置更新、非所有屬性都加前綴、建議配合預處理器使用。

AnimatingSVGwithCSSispossibleusingkeyframesforbasicanimationsandtransitionsforinteractiveeffects.1.Use@keyframestodefineanimationstagesforpropertieslikescale,opacity,andcolor.2.ApplytheanimationtoSVGelementssuchas,,orviaCSSclasses.3.Forhoverorstate-b

theconic-Gradient()functionIncsscreatesCircularGradientsThatRotateColorStopSaroundAcentralPoint.1.IsidealForPieCharts,ProgressIndicators,colordichers,colorwheels和decorativeBackgrounds.2.itworksbysbysbysbydefindefingincolordefingincolorstopsatspecificains off.

Mobile-firstCSSdesignrequiressettingtheviewportmetatag,usingrelativeunits,stylingfromsmallscreensup,optimizingtypographyandtouchtargets.First,addtocontrolscaling.Second,use%,em,orreminsteadofpixelsforflexiblelayouts.Third,writebasestylesformobile,the

創建CSS加載旋轉器的方法有三種:1.使用邊框的基本旋轉器,通過HTML和CSS實現簡單動畫;2.使用多個點的自定義旋轉器,通過不同延遲時間實現跳動效果;3.在按鈕中添加旋轉器,通過JavaScript切換類來顯示加載狀態。每種方法都強調了設計細節如顏色、大小、可訪問性和性能優化的重要性,以提升用戶體驗。

prainuredetectionIncsssusissuse@supportScheckSifabRowsEsuppecifortSupecifortEfeatureBeforeApplyingReplyingStyles.1.itusesconditionalcsssssbasssbasedonproperty-valueperty-valuepairs,suessas@supports@supports@supports@supports(display:grid)

2025年歐洲十大虛擬貨幣交易平台包括Binance、OKX、Coinbase等,依據合規性、安全性、費用、資產種類和用戶體驗評選。 1. Binance:全球交易量最大,費率低,已獲多國牌照;2. OKX:產品全面,技術強,已在法國註冊;3. Coinbase:合規安全,適合初學者,在多國獲許可;4. Gate.io:歷史悠久,安全性高,在歐洲多國註冊;5. Bitstamp:成立早,合規性強,受盧森堡監管;6. eToro:支持社交交易,多元化投資,受CySEC監管;7. Bitpanda:界

HTML5、CSS和JavaScript應通過語義化標籤、合理加載順序與解耦設計高效結合。 1.使用HTML5語義化標籤如、提升結構清晰度與可維護性,利於SEO和無障礙訪問;2.CSS應置於中,使用外部文件並按模塊拆分,避免內聯樣式與延遲加載問題;3.JavaScript推薦放在前引入,使用defer或async異步加載以避免阻塞渲染;4.減少三者間強依賴,通過data-*屬性驅動行為、類名控制狀態,統一命名規範提升協作效率。這些方法能有效優化頁面性能與團隊協作。
