纯css 实现tab效果

原理:
1、radio 与a 重叠,
2、radio zindex属性比a大,
3、radio透明
参考 http://www.imooc.com/video/7144

<html>
<head>
    <style type="text/css">
        .nav {
            position: fixed;
            bottom: 10px;
            width: 100%;
            height: 50px;
        }

        input, a {
            position: absolute;
            width: 20%;
            height: 100%;
        }

        input {
            z-index: 100;
            opacity: 0;
        }

        a {
            text-decoration:none;
            text-align: center;
            background: yellow;
            line-height: 50px;
        }

        .nav_item1, .nav_item1 + a {
            left: 0%;
        }

        .nav_item2, .nav_item2 + a {
            left: 20%;
        }

        .nav_item3, .nav_item3 + a {
            left: 40%;
        }

        .nav_item4, .nav_item4 + a {
            left: 60%;
        }

        .nav input:checked + a {
            background-color: #ff0000;
            font-size: 26px;
        }
    </style>

</head>
<body>
<div class="nav">
    <input type="radio" name="nav_radio" checked="checked" class="nav_item1">
    <a href="#">aa</a>
    <input type="radio" name="nav_radio" class="nav_item2">
    <a href="#">bb</a>
    <input type="radio" name="nav_radio" class="nav_item3">
    <a href="#">cc</a>
    <input type="radio" name="nav_radio" class="nav_item4">
    <a href="#">dd</a>
</div>
</body>
</html>
<html>
<head>
    <style type="text/css">
        .nav {
            position: relative;
        }

        .nav-item {
            display: inline-block;
            width: 20%;
            height: 50px;
            margin-left: 10px;
            position: relative;
        }

        input {
            position: absolute;
            top: 0px;
            left: 0px;
            width: 100%;
            z-index: 100;
            height: 100%;
            opacity: 0;
        }

        a {
            position: absolute;
            top: 0px;
            width: 100%;
            height: 100%;
            text-align: center;
            background: yellow;
            line-height: 50px
        }

        .nav input:checked + a {
            background-color: #ff0000;
            font-size: 26px;
        }
    </style>

</head>
<body>
<div class="nav">
    <div class="nav-item">
        <input type="radio" name="nav_radio" checked="checked">
        <a href="#">aa</a>
    </div>
    <div class="nav-item">
        <input type="radio" name="nav_radio">
        <a href="#">aa</a>
    </div>
    <div class="nav-item">
        <input type="radio" name="nav_radio">
        <a href="#">aa</a>
    </div>
    <div class="nav-item">
        <input type="radio" name="nav_radio">
        <a href="#">aa</a>
    </div>
</div>
</body>
</html>

html简单,css就要复杂点,
html 复杂,css就能简单点,
html 简单至上,后台人员只要看html,当然结构简单更好,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值