Yogesh Chauhan's Blog

How to create a simple tab interaction using CSS?

in CSS on February 7, 2021

We want to create a simple tab view like this one:

Generally we add a link to point to a page but we can also add ‘#id‘ to point it to a specific element.

When we click on the link, browsers will try to focus on the element. At that time, we can adjust the style of the elements to create tab view.

To do that we are going to use the CSS ‘:target‘ selector.

CSS :target Selector

The element we link into a tags using ‘#id‘ to is the target element. So, we can use it to style the current active target element.

We’ll use CSS display property on that targeted element to create the tab interface.

Example


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
The simple difference between var, let and const in JavascriptJavaScriptHow to test the WordPress 5.9 Beta 4?WordPressHow to get user’s Browser and Operating Systems information using PHP?PHPHow to use @supports rule in CSS?CSSWordPress: How to find all posts from a custom post type with multiple custom fields values?WordPressReverse a String in JavaScriptJavaScriptEffects in ReactReactWhat is a “promise” in JavaScript?JavaScriptHow to add transparent text on top of an image using CSS?CSSHow to add AppRoutingModule in Angular application using command line?AngularHow to create a Random Hex Color generator using JavaScript?JavaScriptWordPress: How to print ACF array field values?WordPress