css實現頁面標籤的跳轉
阿新 • • 發佈:2018-12-16
純css實現頁面標籤的跳轉
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>tab</title> <style type="text/css"> #main { width: 510px; margin: 100px auto 0; border: 1px solid #999; background-color: lightgreen; } label { display: inline-block; cursor: pointer; height: 52px; line-height: 52px; font-size: 16px; width: 70px; text-align: center; margin: 0 47px; } .radio { margin: 0; display: none; } .radio:nth-of-type(1):checked~label:nth-of-type(1) { /*當第一個radio是checked的input時選中下面的標籤1增加樣式*/ color: #fff; border-bottom: 2px solid #fff; font-weight: bold; } .radio:nth-of-type(1):checked~.tab:nth-of-type(1) { /*當第一個radio是checked的input時選中下面的內容1增加樣式*/ display: block; } .radio:nth-of-type(2):checked~label:nth-of-type(2) { color: #fff; border-bottom: 2px solid #fff; font-weight: bold; } .radio:nth-of-type(2):checked~.tab:nth-of-type(2) { display: block; } .radio:nth-of-type(3):checked~label:nth-of-type(3) { color: #fff; border-bottom: 2px solid #fff; font-weight: bold; } .radio:nth-of-type(3):checked~.tab:nth-of-type(3) { display: block; } .tab { display: none; width: 100%; height: 240px; font-size: 24px; text-align: center; line-height: 240px; border-top: 1px solid #d8d8d8; background-color: #fff; } </style> </head> <body> <div id="main"> <input checked="checked" id="radio" class="radio" type="radio" name="radio"> <!--單選框radio--> <input id="radio1" class="radio" type="radio" name="radio"> <input id="radio2" class="radio" type="radio" name="radio"> <label for="radio">頁籤1</label> <!--for屬性繫結上面的input標籤--> <label for="radio1">頁籤2</label> <label for="radio2">頁籤3</label> <div class="tab">內容1</div> <div class="tab">內容2</div> <div class="tab">內容3</div> </div> </body> </html>