目录
Create the HTML structure
Style the spinner with CSS
Center the spinner on the page (optional)
首页 web前端 css教程 如何创建简单的CSS加载旋转器

如何创建简单的CSS加载旋转器

Oct 04, 2025 am 03:47 AM
css

创建一个带 class="loader" 的 div 作为加载器。2. 使用 CSS 设置宽高、边框和圆角形成圆形,通过 border-top 颜色差异实现视觉旋转。3. 添加 @keyframes 定义的 spin 动画使其持续旋转。4. 可选地用 flexbox 将加载器居中显示。

How to create a simple css loading spinner

Creating a simple CSS loading spinner doesn't require any images or JavaScript. You can build one using just HTML and CSS with a few lines of code. Here's how to make a basic spinning circle loader.

Create the HTML structure

Start with a single div element that will act as the spinner. Give it a class name like loader for styling.

<div class="loader"></div>

Style the spinner with CSS

Use CSS to create a circular shape and apply a rotating animation. Set border properties to give it a spinning effect.

.loader {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

This creates a border-only circle where only the top part is colored, giving the impression of rotation. The animation property makes it spin continuously.

Center the spinner on the page (optional)

If you want the spinner centered, wrap it in a container and use flexbox.

<div class="loader"></div>

Add this CSS:

.loader-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

That’s it. You now have a clean, smooth-loading spinner. You can adjust size, color, speed, or shape depending on your design needs. Basically just tweak the width, border, or animation duration to customize it.

以上是如何创建简单的CSS加载旋转器的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Stock Market GPT

Stock Market GPT

人工智能驱动投资研究,做出更明智的决策

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

如何使用CSS设计文本方面 如何使用CSS设计文本方面 Sep 16, 2025 am 07:00 AM

首先设置宽度、高度、内边距、边框、字体和颜色等基本样式;2.通过:hover和:focus状态增强交互反馈;3.使用resize属性控制调整大小行为;4.利用::placeholder伪元素样式化占位符文本;5.采用响应式设计确保跨设备可用性;6.注意关联label标签、颜色对比度和焦点轮廓以保障可访问性,最终实现美观且功能完善的textarea样式。

如何使用纯CSS创建下拉菜单 如何使用纯CSS创建下拉菜单 Sep 20, 2025 am 02:19 AM

使用HTML和CSS可创建无需JavaScript的下拉菜单。2.通过:hover伪类触发子菜单显示。3.利用嵌套列表构建结构,CSS设置隐藏与悬浮显示效果。4.可添加过渡动画提升视觉体验。

如何防止图像拉伸或缩小CSS 如何防止图像拉伸或缩小CSS Sep 21, 2025 am 12:04 AM

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

如何使用CSS中的指针事件属性 如何使用CSS中的指针事件属性 Sep 17, 2025 am 07:30 AM

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

如何使用CSS添加盒子阴影效果 如何使用CSS添加盒子阴影效果 Sep 20, 2025 am 12:23 AM

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

如何在CSS中添加梯度背景 如何在CSS中添加梯度背景 Sep 16, 2025 am 05:30 AM

要添加CSS渐变背景,使用background或background-image属性配合linear-gradient()、radial-gradient()等函数即可;首先选择渐变类型,设置方向与颜色,并可通过颜色停靠点、形状、大小等参数精细控制,例如linear-gradient(toright,#ff7e5f,#feb47b)创建从左到右的线性渐变,radial-gradient(circle,#ff9a9e,#fecfef)创建圆形径向渐变,还可通过repeating-linear-gr

如何使CSS响应文字 如何使CSS响应文字 Sep 15, 2025 am 05:48 AM

tomaketExtresponsiveNincss,usereLativeUnitslikerem,vw,and clamp()withMediaqueries.1.ReplaceFlaceFixedPixedPixedPixEdedPixelSwithRemforConsistensCali ngbasedonrootfontsize.2.usevwforfluidscalingbutcombinewithcalc()orclamp()topreventextremes.3.applymediamediaqueriesatcommonbreakpo

如何在CSS中创建圆形图像? 如何在CSS中创建圆形图像? Sep 15, 2025 am 05:33 AM

使用border-radius:50%将等宽高的图像变为圆形,结合object-fit和aspect-ratio确保形状和裁剪,可添加边框、阴影等样式增强视觉效果。

See all articles