Introducing an example code for making tabs using pure CSS

零下一度
Release: 2017-05-05 15:42:05
Original
1390 people have browsed it

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>
Copy after login

Effect:

Introducing an example code for making tabs using pure CSS

[Related recommendations]

1. Free css online video tutorial

2. css online manual

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template