资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

css3radio样式,css设置radio样式

纯css3:radio+label实现轮播图

预览地址: 纯css3:radio+label实现轮播图

靖宇ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

轮播图这东西,我相信只要是做前端的,肯定都做过,不过大部分应该都是用js来实现的,其实css3也是可以实现轮播图的,而且也可以加一些动画之类的,下边就分享下思路。声明,这里没有贬低 js 的意思,相反, js 能做的, css 基本做不到, css 能做的, js 基本能做到,这里纯粹就是为了分享 css 的一些运用。

css 里有个可以绑定到 input 上的标签 label ,它的功能就是当你点击所绑定的这个 label 的时候,就可以选中相应的 input ,既然有了这个功能,那就有了控制轮播图的方法了。

通过 css 可以看到,其实这个例子主要用到的就是 input type="radio" 的 :checked 伪类选择器然后通错 css3 的 :nth-of-type(n) 节点选择器控制与之相对应的轮播、按钮,整个例子也没什么难度,也就不废话了。

如何让input单选框中的对勾变成灰色,不使用disabled

input type="radio"  你直接可以通过样式修改,

你可以参照这篇文章

利用css3修改input[type=radio]样式

如何使用纯CSS3美化单选按钮radio的示例代码分享

HTML代码:

label for="man" class="radio"

span class="radio-bg"/span

input type="radio" name="sex" id="man" value="男" checked="checked" / 男

span class="radio-on"/span

/label

这个方法中最重要的是选中效果的类名:.radio input:checked + span.radio-on

+是CSS2的伪类,其意义为:p+p 选择紧接在 p 元素之后的所有 p 元素。

也就是找到选中的(:checked)的input,其之后的类名为radio-on的span元素做选中圆圈效果。

网上有很多美化方法是把label做成了圆圈,但是这样的话,单选的文字就必须要要放到label的外面,这导致了点击文字的时候,不能切换单选效果。

所以我在label里加了一个类名为radio-bg的span来专门做后面大的圆圈,再用一个类名为radio-on的span来做选中的前面小的圆圈。

这样就保留了点击label里的文字,也可以切换单选的效果。

以上就是如何使用纯CSS3美化单选按钮radio的示例代码分享的方法

如何使用css3技术实现幻灯片效果

使用css3技术实现幻灯片效果

HTML主要包括了3个主要部分:radio按钮和标签,容器,及其标题,如下:

section class="cr-container"

!-- radio buttons and labels --

input id="select-img-1" name="radio-set-1" type="radio" class="cr-selector-img-1" checked/

label for="select-img-1" class="cr-label-img-1"1/label

input id="select-img-2" name="radio-set-1" type="radio" class="cr-selector-img-2" /

label for="select-img-2" class="cr-label-img-2"2/label

input id="select-img-3" name="radio-set-1" type="radio" class="cr-selector-img-3" /

label for="select-img-3" class="cr-label-img-3"3/label

input id="select-img-4" name="radio-set-1" type="radio" class="cr-selector-img-4" /

label for="select-img-4" class="cr-label-img-4"4/label

div class="clr"/div

CSS3新增的哪些选择器和常见的属性是哪些?

一、新增的选择器

CSS3新增的属性选择器 {除ie6外的大部分浏览器支持)

1    E[att^="val"]    属性att的值以"val"开头的元素    div[id^="nav"] { background:#ff0; } 

2    E[att$="val"]    属性att的值以"val"结尾的元素       

3    E[att*="val"]    属性att的值包含"val"字符串的元素       

结构伪类选择器(过滤选择器)

(注:FireFox 1.5/2.0/3.0支持E:root,FireFox 3.0支持E:last-child、E:only-child、E:empty。

由于IE6/7/8不支持,没办法,选择合适的场合用吧。)

4    E:root    匹配文档的根元素,对于HTML文档,就是HTML元素       

5    E:nth-child(n)    匹配其父元素的第n个子元素,第一个编号为1    p:nth-child(3) { color:#f00; }  

6    E:nth-last-child(n)    匹配其父元素的倒数第n个子元素,第一个编号为1    p:last-child { background:#ff0; }  

7    E:nth-of-type(n)    与:nth-child()作用类似,但是仅匹配使用同种标签的元素    p:nth-of-type(2){color:red;}选择父元素的第n个子元素p  

8    E:nth-last-of-type(n)    与:nth-last-child() 作用类似,但是仅匹配使用同种标签的元素       

9    E:last-child    匹配父元素的最后一个子元素,等同于:nth-last-child(1)       

10    E:first-of-type    匹配父元素下使用同种标签的第一个子元素,等同于:nth-of-type(1)       

11    E:last-of-type    匹配父元素下使用同种标签的最后一个子元素,等同于:nth-last-of-type(1)       

12    E:only-child    匹配父元素下仅有的一个子元素,等同于:first-child:last-child或 :nth-child(1):nth-last-child(1)    p:only-child { background:#ff0; }  

13    E:only-of-type    匹配父元素下使用同种标签的唯一一个子元素,等同于:first-of-type:last-of-type或 :nth-of-type(1):nth-last-of-type(1)       

14    E:empty    匹配一个不包含任何子元素的元素,注意,文本节点也被看作子元素    p:empty { background:#ff0; }  

与用户界面(UI)有关的伪类(ie6 7 8不支持)    

15    E:enabled    匹配表单中激活的元素       

16    E:disabled    匹配表单中禁用的元素    input[type="text"]:disabled { background:#ddd; }  

17    E:checked    匹配表单中被选中的radio(单选框)或checkbox(复选框)元素       

18    E::selection    匹配用户当前选中的元素       

级元素通用选择器

ie6不支持 

19    E ~ F    匹配任何在E元素之后的同级F元素    p ~ ul { background:#ff0; }  

反选伪类

(ie6 7 8 firefox3.0以下 Opera9.0不支持)  

20    E:not(s)    匹配不符合当前选择器的任何元素    :not(p) { border:1px solid #ccc; }  

:target 伪类

(ie6 7 8不支持)  

21    E:target    匹配文档中特定"id"点击后的效果       

二、css3新增属性

一. box-shadow(阴影效果)

使用:

box-shadow: 20px 10px 0 #000;

-moz-box-shadow: 20px 10px 0 #000;

-webkit-box-shadow: 20px 10px 0 #000;

支持:

FF3.5, Safari 4, Chrome 3

二. border-colors(为边框设置多种颜色)

使用:

border: 10px solid #000;

-moz-border-bottom-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;

-moz-border-top-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;

-moz-border-left-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;

-moz-border-right-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;

说明:

颜色值数量不固定, 且FF的私有写法不支持缩写: -moz-border-colors: #333 #444 #555;

支持:

FF3+

三. boder-image(图片边框)

使用:

-moz-border-image: url(exam.png) 20 20 20 20 repeat;

-webkit-border-image: url(exam.png) 20 20 20 20 repeat;

说明:

(1). 20 20 20 20 --- 边框的宽度, 分别对应top, right, bottom, left边框, 改变宽度可以实现不同的效果;

(2). 边框图片效果(目前仅实现了两种):

repeat --- 边框图片会平铺, 类似于背景重复;

stretch --- 边框图片会以拉伸的方式来铺满整个边框;

(3). 必须将元素的边框厚度设置为非0非auto值.

支持:

FF 3.5, Safari 4, Chrome 3

四. text-shadow(文本阴影)

使用:

text-shadow: [颜色水平偏移纵向偏移模糊半径] || [水平偏移纵向偏移模糊半径颜色];

说明:

(1) 颜色和模糊半径是可选的, 当颜色未指定时, 将使用文本颜色; 当模糊半径未指定时, 半径值为0;

(2) shadow可以是逗号分隔的列表, 如:

text-shadow: 2px 2px 2px #ccc, 3px 3px 3px #ddd;

(3) 阴影效果会按照shadow list中指定的顺序应用到元素上;

(4) 这些阴影效果有可能相互重叠, 但不会叠加文本本身;

(5) 阴影可能会跑到容器的边界之外, 但不会影响容器的大小.

支持:

FF 3.5, Opera 10, Safari 4, Chrome 3

五.  text-overflow(文本截断)

使用:

text-overflow: inherit | ellipsis | clip ;

-o-text-overflow: inherit | ellipsis | clip;

说明:

(1) 还有一个属性ellipsis-word, 但各浏览器均不支持.

支持:

IE6+, Safari4, Chrome3, Opera10

六. word-wrap(自动换行)

使用:

word-wrap: normal | break-word;

支持:

IE6+, FF 3.5, Safari 4, Chrome 3

七. border-radius(圆角边框)

使用:

-moz-border-radius: 5px;

-webkit-border-radius: 5px;

支持:

FF 3+, Safari 4 , Chrome 3

八.   opacity(不透明度)

使用:

opacity: 0.5;

filter: alpha(opacity=50); /* for IE6, 7 */

-ms-filter(opacity=50); /* for IE8 */

支持:

all

九. box-sizing(控制盒模型的组成模式)

使用:

box-sizing: content-box | border-box; // for opera

-moz-box-sizing: content-box | border-box;

-webkit-box-sizing: content-box | border-box;

说明:

1. content-box:

使用此值时, 盒模型的组成模式是, 元素宽度 = content + padding + border;

2. border-box:

使用此值时, 盒模型的组成模式是, 元素宽度 = content(即使设置了padding和border, 元素的宽度

也不会变).

支持:

FF3+, Opera 10, Safari 4, Chrome 3

十. resize(元素缩放)

使用:

resize:  none | both | horizontal | vertical;

说明:

1. 必须将元素的overflow属性设置为auto或hidden, 该属性才能起作用(overflow设置为visible时, 无效);

2. 属性值说明:

(1). none -- 禁用缩放;

(2). both -- 可同时缩放宽度和高度;

(3). horizontal -- 仅能缩放宽度;

(4). vertical -- 仅能缩放高度;

支持:

safari 4, chrome 3

十一. outline(外边框)

使用:

outline: 边框厚度 边框样式 边框颜色;

outline-offset: 偏移值;

说明:

outline-offset需要独立写, 简写是无效的.

支持:

FF3+, safari 4, chrome 3, opera 10

十二. background-size(指定背景图片的尺寸)

使用:

-o-background-size: [length | percentage] {1, 2};

-webkit-background-size: [length | percentage] {1, 2};

例如:

-o-background-size: 50px 60px;

-webkit-background-size: 50px 60px;

这会将背景图片的宽设置了50px, 高60px.

支持:

safari 4, chrome 3, opera 10

十三. background-origin(指定背景图片从哪里开始显示)

使用:

-webkit-background-origin: border | padding | content;

-moz-background-origin: border | padding | content;

说明:

(1) border -- 从border区域开始显示背景;

(2) padding -- 从padding区域开始显示背景;

(3) content -- 从content区域开始显示背景;

注意:

1. 必须先指定background属性, 然后才能指定该属性, 如果该属性出现在background属性之前,

会无效.

支持:

safari 4, chrome 3, FF 3+        

十四. background-clip(指定背景图片从什么位置开始裁切)

使用:

-webkit-background-origin: border-box | padding-box | content-box | no-clip;

说明:

(1) border-box -- 从border区域向外裁剪背景;

(2) padding-box -- 从padding区域向外裁剪背景;

(3) content-box -- 从content区域向外裁剪背景;

(4) no-clip -- 不裁切背景.

注意:

1. 必须先指定background属性, 然后才能指定该属性, 如果该属性出现在background属性之前,

会无效.

支持:

safari 4, chrome 3

十五.  background(为一个元素指定多个背景)

使用:

background:  [background-image] | [background-origin] | [background-clip] | [background-repeat] | [background-size] | [background-position]

例子:

background: url(bg1.png) no-repeat left top, url(bg2.png) no-repeat right bottom;

支持:

safari 4, chrome 3

十六. hsl(通过色调, 饱和度, 亮度来指定颜色值)

使用:

hsl: ( length || percentage || percentage);

说明:

(1) length: h(色调),  0(或360)表示红色, 120表示绿色, 240表示蓝色;

(2) percentage: s(饱和度),  取值为0%到100%之间的值;

(3) percentage: l(亮度),  取值为0%到100%之间的值;

例子:

background: hsl(240, 50%, 100%);

color: hsl(100, 80, 100%);

支持:

safari 4, chrome 3, FF3, opera 10

十七. hsla(在hsl的基础上上增加了一个透明度设置)

使用:

hsla: ( length  ||  percentage  ||  percentage || opacity);

说明:

(1) opacity: a(透明度), 取值在0到1之间;

例子:

background: hsl(240, 50%, 100%, 0.5);

color: hsl(240, 50%, 100%, 0.5);

支持:

safari 4, chrome 3, FF3, opera 10

十八. rgba(基于r,g,b三个颜色通道来设置颜色值, 通过a来设置透明度)

使用:

rgba: (r, g, b, opacity);

说明:

(1) r: 红色, 正整数 | 百分数;

(2) g: 绿色, 正整数 | 百分数;

(3) b: 蓝色, 正整数 | 百分数;

(4) a: 透明度, 取值在0到1之间;

(5) 正整数在0到255之间, 百分数在0%到100%之间.

例子:

rgba: (100%, 244, 0, 0.5);

支持:

safari 4, chrome 3, FF3, opera 10

十九、 transition(a标签hover渐隐效果)

a:hover{transition: color 0.15s linear 0s, background-color 0.3s linear 0s;}

-webkit-transition:color 0.15s linear 0s, background-color 0.3s linear 0s;

-moz-transition:color 0.15s linear 0s, background-color 0.3s linear 0s;

-o-transition:color 0.15s linear 0s, background-color 0.3s linear 0s;

-ms-transition:color 0.15s linear 0s, background-color 0.3s linear 0s;

transition:color 0.15s linear 0s, background-color 0.3s linear 0s;


文章名称:css3radio样式,css设置radio样式
文章出自:http://cdkjz.cn/article/dsdhioi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220