Method 1. Use the anchor point of the a tag to achieve tab switching
(Recommended tutorial: CSS tutorial)
Code As follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>cssTab切换2</title> <style type="text/css"> *{ margin: 0; padding: 0; text-decoration: none; } .tab{ width: 300px; height: 300px; margin: 30px auto; overflow: hidden; } .nav{ height: 30px } .content{ height: 270px; overflow: hidden; } .cont{ height: 270px; } #the1{ background: green; } #the2{ background: blue; } </style> </head> <body> <div class="tab"> <div class="nav"> <a href="#the1">ONE</a> <a href="#the2">TWO</a> </div> <div class="content"> <div id="the1" class="cont">第一张</div> <div id="the2" class="cont">第二张</div> </div> </div> </body> </html>
(Learning video recommendation: css video tutorial)
Method 2, use the radio button and :checked selector
The code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>纯css实现tab切换</title> <style type="text/css"> *{ margin: 0; padding: 0; } .tab{ width: 300px; height: 150px; margin-left: 30px; margin-top: 30px; border: 1px solid #eee; position: relative; overflow: hidden; } input[type='radio']{ display: none; } .tab label{ display: block; cursor: pointer; position: absolute; width: 60px; height: 30px; line-height: 30px; text-align: center; border: 1px solid #eee; } .label-1{ left: 0; top: 0; } .label-2{ left: 60px; top: 0; } input[type='radio']:checked~div[class^='mod']{ display: block; } input[type='radio']:checked~label{ background: orange; } [class^='mod']{ position: absolute; top: 40px; left: 20px; display: none; } </style> </head> <body> <div class="tab"> <div> <input type="radio" id="r-1" name="tab" checked> <label for="r-1" class="label-1">第一张</label> <div class="mod-1"> <ul> <li>275万购昌平邻铁三居</li> <li>总价20万买一居</li> <li>200万内购五环三居</li> <li>北京首现零首付楼盘</li> </ul> </div> </div> <div> <input type="radio" id="r-2" name="tab"> <label for="r-2" class="label-2">第二张</label> <div class="mod-2"> <ul> <li>新中式的酷色温情</li> <li>深圳房价大跌,每平8W</li> <li>800万买沙井三房</li> <li>宝安房价平均900W</li> </ul> </div> </div> </div> </body> </html>
The above is the detailed content of How to implement Tab switching in css. For more information, please follow other related articles on the PHP Chinese website!

On March 6, 2018, a new bug was added to the official Mozilla Firefox browser bug tracker. A developer had noticed an issue with Mozilla's nightly build. The

I’ve been hearing a lot about design tokens lately, and although I’ve never had to work on a project that’s needed them, I think they’re super interesting and

Map, reduce, and filter are three very useful array methods in JavaScript that give developers a ton of power in a short amount of space. Let’s jump right

Over the course of the last four articles in this five-part series, we’ve taken a broad look at the technologies that make up the Web Components standards.

I’ve been wondering for a good long while why it feels like web design and development isn’t respected as much as native app development, and why the

Having been tasked with creating a UI component for navigating the content of an online course, Daniel found himself neck-deep in a pool of new CSS features that he wound up using on the project.

Andy Bell wrote up his thoughts about the whole web versus native app debate which I think is super interesting. It was hard to make it through the post

I've seen a handful of recent posts talking about the utility of the :is() relational pseudo-selector. No need to delve into the details other than to say it


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools