<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>纯csstab</title> <style type="text/css"> * { margin: 0; padding: 0; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; } body { padding: 20px; text-align: left; font-family: Lato; color: #fff; background: #9b59b6; } .tabs { width: 650px; float: none; list-style: none; position: relative; margin: 80px 0 0 10px; text-align: left; } .tabs li { float: left; display: block; } .tabs input[type="radio"] { position: absolute; top: -9999px; left: -9999px; } .tabs label { display: block; padding: 14px 21px; border-radius: 2px 2px 0 0; font-size: 20px; font-weight: normal; text-transform: uppercase; background: #8e44ad; cursor: pointer; position: relative; top: 4px; -moz-transition: all 0.2s ease-in-out; -o-transition: all 0.2s ease-in-out; -webkit-transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out; } .tabs label:hover { background: #703688; } .tabs .tab-content { z-index: 2; display: none; overflow: hidden; width: 100%; font-size: 17px; line-height: 25px; padding: 25px; position: absolute; top: 53px; left: 0; background: #612e76; } .tabs [id^="tab"]:checked + label { top: 0; padding-top: 17px; background: #612e76; } .tabs [id^="tab"]:checked ~ [id^="tab-content"] { display: block; } </style> </head> <body> <ul class="tabs"> <li> <input type="radio" name="tabs" id="tab1" checked /> <label for="tab1">Description</label> <div id="tab-content1" class="tab-content"> <p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p> </div> </li> <li> <input type="radio" name="tabs" id="tab2" /> <label for="tab2">Specification</label> <div id="tab-content2" class="tab-content"> <p>"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla?</p> </div> </li> </ul> <br style="clear: both;" /> </body> </html> 提示:你可以先修改部分代码再运行。 http://codepen.io/wallaceerick/pen/ojtal 转载请注明:有爱前端 » 纯css tab 喜欢 (0)or分享 (0)