纯CSS实现table切换;lable+radio组合,仅供参考思路

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>纯css-label+radio组成tab切换</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<style>
.main{
    position: relative;
    width: 1200px;
    height: 800px;
/*    border: 1px solid red;*/
    margin: 0 auto;
}
.photo{
    position: absolute;
    right: 0px;
    left: -480px;
}
label{
    cursor: pointer;
    display: inline-block;
    opacity: 0.5;
    height: 100px;
    width: 230px;
    margin-top: 100px;
    background-color: transparent;
    border-radius: 4px;
    text-align: center;
    border: 1px solid black;
    line-height: 100px;
}
label:hover{
opacity: 1;
}
input{
display:none;
}
ul{
    list-style: none;
    padding: 0px;
    height: 320px;
    overflow: hidden;
    margin-left: 480px;
    position: relative;
}
.set_page1:checked + ~.photo ul li:nth-child(1){
    position: absolute;
    top: 0px;
    z-index: 25;
    width: 1180px;
}
.set_page2:checked ~.photo ul li:nth-child(2){
    position: absolute;
    top: 0;
    z-index: 22;
    width: 1180px;
}
.set_page3:checked ~.photo ul li:nth-child(3){
    position: absolute;
    top: 0;
    z-index: 23;
    width: 1180px;
}
.set_page4:checked ~.photo ul li:nth-child(4){
    position: absolute;
    top: 0;
    z-index: 24;
    width: 1180px;
}


.set_page5:checked ~.photo ul li:nth-child(5){
    position: absolute;
    top: 0;
    width: 1180px;
}
.texts{
    width:1180px;
    height: 318px;
    border: 1px solid black;
    border-radius: 4px;
    overflow: hidden;
    overflow-y: inherit;
}
</style>
</head>
<body>
    <div class="main">
            <input type="radio" name="p" id="name1" class="set_page1"/>
            <input type="radio" name="p" id="name2" class="set_page2"/>
            <input type="radio" name="p" id="name3" class="set_page3"/>
            <input type="radio" name="p" id="name4" class="set_page4"/>
            <input type="radio" name="p" id="name5" class="set_page5"/>
            
            <!--lable中的for需要绑定对应的input的id-->
            <label for="name1" class="c1">第一页</label>
            <label for="name2" class="c2">第二页</label>
            <label for="name3" class="c3">第三页</label>
            <label for="name4" class="c4">第四页</label>
            <label for="name5" class="c5">第五页</label>    
            <div class="photo">
                <ul>
                    <li class="li1">
                        <!-- <img src="http://pic.qiantucdn.com/images/banner/5a254c9364060.jpg"/> -->
                        <div class="texts">内容</div>
                    </li>
                    <li>
                        <!-- <img src="http://pic.qiantucdn.com/images/banner/5a21328de4e82.jpg"/> -->
                        <div class="texts">内容1</div>
                    </li>
                    <li>
                        <!-- <img src="http://pic.qiantucdn.com/images/banner/5a1545ec5960a.jpg"/> -->
                        <div class="texts">内容2</div>
                    </li>
                    <li>
                        <!-- <img src="http://pic.qiantucdn.com/images/banner/5a1bc5717486e.jpg"/> -->
                        <div class="texts">内容3</div>
                    </li>
                    <li>
                       <!--  <img src="http://pic.qiantucdn.com/images/banner/59f7d0b097669.jpg"/> -->
                       <div class="texts">内容4</div>
                    </li>
                </ul>
            </div>
        </div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 table切换代码,你可以根据自己的需求进行修改和优化: HTML: ```html <div class="tab"> <button class="tab-button active" onclick="openTab(event, 'tab1')">Tab 1</button> <button class="tab-button" onclick="openTab(event, 'tab2')">Tab 2</button> <button class="tab-button" onclick="openTab(event, 'tab3')">Tab 3</button> </div> <div id="tab1" class="tab-content active">Tab 1 Content</div> <div id="tab2" class="tab-content">Tab 2 Content</div> <div id="tab3" class="tab-content">Tab 3 Content</div> ``` CSS: ```css .tab { display: flex; justify-content: center; margin-bottom: 20px; } .tab-button { background-color: #eee; border: none; outline: none; cursor: pointer; padding: 10px 20px; margin: 0 10px; border-radius: 5px 5px 0 0; } .tab-button:hover { background-color: #ddd; } .tab-button.active { background-color: #fff; border-bottom: 2px solid #333; } .tab-content { display: none; padding: 20px; border: 2px solid #333; border-top: none; } .tab-content.active { display: block; } ``` JavaScript: ```javascript function openTab(evt, tabName) { var i, tabcontent, tabbuttons; tabcontent = document.getElementsByClassName("tab-content"); for (i = 0; i < tabcontent.length; i++) { tabcontent[i].style.display = "none"; } tabbuttons = document.getElementsByClassName("tab-button"); for (i = 0; i < tabbuttons.length; i++) { tabbuttons[i].className = tabbuttons[i].className.replace(" active", ""); } document.getElementById(tabName).style.display = "block"; evt.currentTarget.className += " active"; } ``` 以上代码实现了一个简单的 table切换,可以通过点击不同的标签来显示不同的内容。你可以根据自己的需求进行修改和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值