码迷,mamicode.com
首页 > Web开发 > 详细

利用radio实现纯css选项卡切换

时间:2015-09-20 16:16:35      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

代码文件如下:

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>radio选项卡切换</title>
 6     <style type="text/css">
 7         *{margin:0;padding:0;}
 8         .test-box{width: 50%;margin: 10px auto 0;padding-top: 25px;position: relative;}
 9         .test-box>.test-tab{width:100%;}
10         .test-box .test-label{background-color: #eee;display: inline-block;width: 25%;text-align: center;font-size: 16px;line-height: 24px;box-sizing: border-box;}
11         .test-label{position: absolute;top: 0;border:solid #ccc; border-width:1px 0px 1px 1px;}
12         .test-tab:nth-child(1) .test-label{left: 0;}
13         .test-tab:nth-child(2) .test-label{left: 25%;}
14         .test-tab:nth-child(3) .test-label{left: 50%;}
15         .test-tab:last-child .test-label{border-right-width:1px;}
16         .test-box .content{background-color: #fff;height: 20px;display: none;border:1px solid #ccc;}
17         .test-box input.test-radio{display: none;}
18         .test-box input:checked~.test-label{background-color: #fff;border-bottom: 1px solid #fff;}
19         .test-box input:checked~.content{display: block;}
20     </style>
21 </head>
22 <body>
23     <div class="test-box">
24         <div class="test-tab">
25             <input type="radio" class="test-radio" id="radio1" name="test-radio" checked>
26             <label for="radio1" class="test-label">选项卡1</label>
27             <div class="content"><P>asdasdsad1</P></div>
28         </div>
29         <div class="test-tab">
30             <input type="radio" class="test-radio" id="radio2" name="test-radio">
31             <label for="radio2" class="test-label">选项卡2</label>
32             <div class="content"><P>asdasdsad2</P></div>
33         </div>
34         <div class="test-tab">
35             <input type="radio" class="test-radio" id="radio3" name="test-radio">
36             <label for="radio3" class="test-label">选项卡3</label>
37             <div class="content"><P>asdasdsad3</P></div>
38         </div>
39     </div>
40 </body>
41 </html>

 

利用radio实现纯css选项卡切换

标签:

原文地址:http://www.cnblogs.com/mengxuan/p/4823541.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!