分享一款纯CSS3水平控制导航菜单和选择项
2014-06-13 00:00
477 查看
分享一款基于纯CSS3的水平控制导航菜单源码,它有3种不同的颜色风格,菜单数量的数量可以自己定义,鼠标点击按钮时背景色块将会缓慢移动到所在的菜单位置。
除了使用菜单,大家还可以用这个来做水平控制开关按钮。效果应该也很不错。我们可以用它来控制用户的选择项。
下面分享一下第一个菜单的源码
再来看一段CSS3代码:
[/i]源码下载 [/i]演示地址
除了使用菜单,大家还可以用这个来做水平控制开关按钮。效果应该也很不错。我们可以用它来控制用户的选择项。
下面分享一下第一个菜单的源码
<nav class="segmented-control segmented-control--turquoise" style="width: 600px;"> <input type="radio" name="sc-0" id="sc-0-1" /> <input type="radio" name="sc-0" id="sc-0-2" checked="checked" /> <input type="radio" name="sc-0" id="sc-0-3" /> <input type="radio" name="sc-0" id="sc-0-4" /> <label for="sc-0-1" data-value="Lorem Ipsum">Lorem Ipsum</label> <label for="sc-0-2" data-value="Cras justo">Cras justo</label> <label for="sc-0-3" data-value="Tellus Etiam">Tellus Etiam</label> <label for="sc-0-4" data-value="Lorem Pellentesque">Lorem Pellentesque</label> </nav>大家可以看到有四个是否选中的input隐藏在里面,类型都是radio的。鼠标点击相关的菜单选项时,表示用户已经选中这个选项。相应id的input就会checked选中。
再来看一段CSS3代码:
.segmented-control > input[type='radio']:nth-child(1):checked ~ label:first-of-type:nth-last-of-type(1):after, .segmented-control > input[type='checkbox']:nth-child(1):checked ~ label:first-of-type:nth-last-of-type(1):after, .segmented-control > input[type='radio']:nth-child(1):checked ~ label:first-of-type:nth-last-of-type(1):before, .segmented-control > input[type='checkbox']:nth-child(1):checked ~ label:first-of-type:nth-last-of-type(1):before, .segmented-control > input[type='radio']:nth-child(1):checked ~ label:first-of-type:nth-last-of-type(1) ~ label:after, .segmented-control > input[type='checkbox']:nth-child(1):checked ~ label:first-of-type:nth-last-of-type(1) ~ label:after, .segmented-control > input[type='radio']:nth-child(1):checked ~ label:first-of-type:nth-last-of-type(1) ~ label:before, .segmented-control > input[type='checkbox']:nth-child(1):checked ~ label:first-of-type:nth-last-of-type(1) ~ label:before { left: 0; } .segmented-control > input[type='radio']:nth-child(2):checked ~ label:first-of-type:nth-last-of-type(2):after, .segmented-control > input[type='checkbox']:nth-child(2):checked ~ label:first-of-type:nth-last-of-type(2):after, .segmented-control > input[type='radio']:nth-child(2):checked ~ label:first-of-type:nth-last-of-type(2):before, .segmented-control > input[type='checkbox']:nth-child(2):checked ~ label:first-of-type:nth-last-of-type(2):before, .segmented-control > input[type='radio']:nth-child(2):checked ~ label:first-of-type:nth-last-of-type(2) ~ label:after, .segmented-control > input[type='checkbox']:nth-child(2):checked ~ label:first-of-type:nth-last-of-type(2) ~ label:after, .segmented-control > input[type='radio']:nth-child(2):checked ~ label:first-of-type:nth-last-of-type(2) ~ label:before, .segmented-control > input[type='checkbox']:nth-child(2):checked ~ label:first-of-type:nth-last-of-type(2) ~ label:before { left: 50%; }可以看到是通过相关CSS类的 :nth-child(n) 选择器匹配属于其父元素的第 N 个子元素,再通过:nth-of-type(n) 选择器匹配属于父元素的特定类型的第 N 个子元素的每个元素.通过控制left的像素位置的来实现颜色的变化位置和相应的移动位置。
[/i]源码下载 [/i]演示地址
相关文章推荐
- css3与html5实现响应式导航菜单(导航栏)效果分享
- 一款基于jquery和css3的响应式二级导航菜单
- 本站在用的一款炫丽过渡的CSS3导航菜单
- 一款纯css3实现的环形导航菜单
- 实列教程 一款基于jquery和css3的响应式二级导航菜单
- 7款风格新颖的jQuery/CSS3菜单导航分享
- css3实例教程 一款纯css3实现的环形导航菜单
- 一款基于jquery和css3的响应式二级导航菜单
- 一款基于jquery和css3的响应式二级导航菜单
- 一款纯css3实现的环形导航菜单
- 7款风格新颖的jQuery/CSS3菜单导航分享
- CSS3制作的一款很酷的错位式导航菜单,可用于博客
- 一款基于jquery和css3的响应式二级导航菜单
- CSS Cookbook创建水平导航菜单
- 分享14个很酷的jQuery导航菜单插件
- 青灰色鼠标滑过换色很大气的一款导航菜单代码
- 分享20款漂亮实用的WEB2.0导航菜单源码下载
- 分享20个漂亮强大的jQuery导航菜单
- 自己做一款不错的二级导航菜单
- 15款优秀的jQuery导航菜单插件分享