CSS3里怎么实现单选框动画特效
CSS3里怎么实现单选框动画特效?为什么要实现单选框动画特效?下面我们给大家举俩个例子,帮大家熟练掌握用CSS3实现单选框动画特效
<div> <input type="radio" name="radio-1" id="radio-1-1" checked="checked"> <label for="radio-1-1"></label> <input type="radio" name="radio-1" id="radio-1-2"> <label for="radio-1-2"></label> <input type="radio" name="radio-1" id="radio-1-3"> <label for="radio-1-3"></label> </div>
这里,我们指定 input 标签的 type 值为 radio,并且一下所有的 radio 的 name 值都相同,这样才可以实现单选效果。对于这里的 label 中的 for 属性,为什么这么设置一开始我也不明白,后来搜索了一下这个属性的定义,反正大概的意思就是说,只要设置了这个属性,当我们点击label 元素的时候,浏览器会自动把焦点转移到 radio 上去。下面用 CSS 对HTML设置效果。
.radio-1 { width: 900px; padding: 3% 0%; margin: 10px auto; background-color: darkseagreen; text-align: center; } .radio-1 label { display: inline-block; position: relative; width: 28px; height: 28px; border: 1px solid #cccccc; border-radius: 100%; cursor: pointer; background-color: #ffffff; margin-right: 10px; }
这里我们首先看一下对 label 元素的设定,其中大部分属性我都在以前的文章中介绍过了,唯一一个陌生的属性就是 cursor,这个属性是设定鼠标样式的,设置成 pointer 之后,当我们的鼠标放到 label 元素上时,鼠标样式就变成了一只手(在我电脑上是这样)。好了,下面继续来看
.radio-1 label:after { content: ""; position: absolute; width: 20px; height: 20px; top: 4px; left: 4px; background-color: #666; border-radius: 50%; transform: scale(0); transition: transform .2s ease-out; }
这里我们用到了 after 选择器,为什么设置这个属性?就是为了设置如上图所示的小黑点。首先我们设置 content 属性为空,意思就是我们不需要填充任何内容,因为我们只是想设置背景色为黑色,仅此而已。还有,刚开始的时候我们设置 transform 的 scale 值为 0 ,其达到的效果就是将小黑点隐藏。
.radio-1 [type="radio"]:checked + label { background-color: #eeeeee; transition: background-color .2s ease-in; } .radio-1 [type="radio"]:checked + label:after { transform: scale(1); transition: transform .2s ease-in; }
注意这里使用了 + 符号,是什么意思呢?它的学名叫做 相邻同胞选择器,意思就是选择紧接在另一个元素后的元素,而且二者有相同的父元素,在这里的意思就是选中在radio 后出现的 label ,有人要问了,这么设置干嘛,直接设置 label 就是了。想象一下,在一个 非常庞大的系统中,我们可能多次使用到 label 元素,为了避免混淆,这样设置将更加准确。这里我们看到了 transition 属性,这个属性是用于设置过渡效果的。最后,将我们的 radio 隐藏掉,就大功告成了。
.radio-1 [type="radio"]{ display: none; } Action two
这是我们的第二个特效
demo2.gif
其实看到这个动画的第一感觉就是,和上一个一模一样,除了将 transform 属性设置成 rotate,下面我就不再解释了,只要你结合上一个例子,就可以很容易做出这么一个效果,我们直接上代码:
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Radio</title> <style> .radio-2 { width: 900px;padding: 3% 0; margin: 50px auto; background-color: darkseagreen; text-align: center; } .radio-2 label { display: inline-block; width: 28px; height: 28px; overflow: hidden; border: 1px solid #eeeeee; border-radius: 100%; margin-right: 10px; background-color: #ffffff; position: relative;cursor: pointer; } .radio-2 label:after { content: ""; position: absolute;top: 4px; left: 4px; width: 20px; height: 20px; background-color: #666666; border-radius: 50%; transform: rotate(-180deg);transform-origin: -2px 50%; transition: transform .2s ease-in; } .radio-2 [type="radio"] { display: none; } .radio-2 [type="radio"]:checked + label:after{ transform: rotate(0deg); transition: transform .2s ease-out; } </style></head><body><div> <input type="radio" name="radio-2" id="radio-2-1" checked="checked"> <label for="radio-2-1"></label> <input type="radio" name="radio-2" id="radio-2-2"> <label for="radio-2-2"></label> <input type="radio" name="radio-2" id="radio-2-3"> <label for="radio-2-3"></label></div></body><ml>
相信大家看了这俩个列子都已经清楚了在CSS3里怎么实现单选框动画特效,更多精彩请关注php中文网其它相关文章!
相关阅读:
以上是CSS3里怎么实现单选框动画特效的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

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

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

在 Vue.js 中使用 Bootstrap 分为五个步骤:安装 Bootstrap。在 main.js 中导入 Bootstrap。直接在模板中使用 Bootstrap 组件。可选:自定义样式。可选:使用插件。

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

HTML定义网页结构,CSS负责样式和布局,JavaScript赋予动态交互。三者在网页开发中各司其职,共同构建丰富多彩的网站。

在 Bootstrap 中插入图片有以下几种方法:直接插入图片,使用 HTML 的 img 标签。使用 Bootstrap 图像组件,可以提供响应式图片和更多样式。设置图片大小,使用 img-fluid 类可以使图片自适应。设置边框,使用 img-bordered 类。设置圆角,使用 img-rounded 类。设置阴影,使用 shadow 类。调整图片大小和位置,使用 CSS 样式。使用背景图片,使用 background-image CSS 属性。

创建 Bootstrap 分割线有两种方法:使用 标签,可创建水平分割线。使用 CSS border 属性,可创建自定义样式的分割线。

要设置 Bootstrap 框架,需要按照以下步骤:1. 通过 CDN 引用 Bootstrap 文件;2. 下载文件并将其托管在自己的服务器上;3. 在 HTML 中包含 Bootstrap 文件;4. 根据需要编译 Sass/Less;5. 导入定制文件(可选)。设置完成后,即可使用 Bootstrap 的网格系统、组件和样式创建响应式网站和应用程序。

要调整 Bootstrap 中元素大小,可以使用尺寸类,具体包括:调整宽度:.col-、.w-、.mw-调整高度:.h-、.min-h-、.max-h-

如何使用 Bootstrap 按钮?引入 Bootstrap CSS创建按钮元素并添加 Bootstrap 按钮类添加按钮文本
