Home >Web Front-end >CSS Tutorial >Introducing an example code for making tabs using pure CSS
Use the radio radio button to create a tab effect. If there are several tab pages, you need to add several inputs accordingly. At the same time, the name of each input must be set to be consistent, and the CSS3 sibling element linker is used to change the style. The nav navigation in the tab must be wrapped with label and the corresponding for.
ps: tab does not support IE8 and below, and the box layout IE 6.0-11.0 does not support float replacement
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /> <title>DEMO3</title> <style type="text/css"> /* tab头区域 */ .ui-tab input { display: none } /* 内容区域 */ .ui-tab .ui-content ul { display: none; min-height: 200px; } /* 头部区域选中 */ #new:checked ~ .ui-nav .new, #hot:checked ~ .ui-nav .hot, #video:checked ~ .ui-nav .video { background: #F4BD00; } /* 内容区域选中 */ #new:checked ~ .ui-content .new-list, #hot:checked ~ .ui-content .hot-list, #video:checked ~ .ui-content .video-list { display: block; background: #f6f6f6; } /* tab头部布局 */ .ui-nav ul { display: -webkit-box; display: box; height: 45px; line-height: 45px; background: #fff; } .ui-nav ul > li { -webkit-box-flex: 1; box-flex: 1; text-align: center; } .ui-nav ul > li label { width: 100%; display: block; cursor: pointer; } </style> </head> <body> <!-- --> <p class="ui-tab"> <input type="radio" name="ui-tab" id="new" checked="checked" /> <input type="radio" name="ui-tab" id="hot" /> <input type="radio" name="ui-tab" id="video" /> <p class="ui-nav"> <ul> <li class="new"><label for="new">最新新闻</label></li> <li class="hot"><label for="hot">社会焦点</label></li> <li class="video"><label for="video">最新视频</label></li> </ul> </p> <p class="ui-content"> <ul class="new-list"> <li>tab内容新1</li> </ul> <ul class="hot-list"> <li>tab内容新2…</li> </ul> <ul class="video-list"> <li>tab内容新3…</li> </ul> </p> </p> <!-- --> </body> </html>
Effect:
[Related recommendations]
1. Free css online video tutorial
3. php.cn Dugu Jiujian (2)-css video tutorial
The above is the detailed content of Introducing an example code for making tabs using pure CSS. For more information, please follow other related articles on the PHP Chinese website!