How to make a tabbed website using HTML, CSS and jQuery
Oct 26, 2023 am 09:54 AMHow to use HTML, CSS and jQuery to make a website with tabs
Today, I will introduce to you how to use HTML, CSS and jQuery to make a tab page Websites with tabs. Tags can help us organize and display the content of the website effectively and provide a better user experience. Below is a specific code example.
First, we will use HTML to create the basic structure of the website. We need a parent container that contains the tab, and create a content block corresponding to the tab within it.
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>帶有標(biāo)簽頁的網(wǎng)站</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="tabs"> <ul class="tab-links"> <li class="active"><a href="#tab1">標(biāo)簽1</a></li> <li><a href="#tab2">標(biāo)簽2</a></li> <li><a href="#tab3">標(biāo)簽3</a></li> </ul> <div class="tab-content"> <div id="tab1" class="tab active"> <h2>標(biāo)簽1內(nèi)容</h2> <p>這是標(biāo)簽1的內(nèi)容。</p> </div> <div id="tab2" class="tab"> <h2>標(biāo)簽2內(nèi)容</h2> <p>這是標(biāo)簽2的內(nèi)容。</p> </div> <div id="tab3" class="tab"> <h2>標(biāo)簽3內(nèi)容</h2> <p>這是標(biāo)簽3的內(nèi)容。</p> </div> </div> </div> <script src="jquery.min.js"></script> <script src="script.js"></script> </body> </html>
Next, we will use CSS to style our tabs. We will use flex layout to implement the arrangement of labels and content blocks, as well as some basic styling.
body { font-family: Arial, sans-serif; margin: 0; padding: 0; } .tabs { margin: 20px; } .tab-links { display: flex; list-style: none; padding: 0; } .tab-links li { margin-right: 10px; } .tab-links li a { display: block; padding: 10px; background-color: #ccc; text-decoration: none; color: #000; border-radius: 5px 5px 0 0; } .tab-links li.active a { background-color: #fff; } .tab-content { border: 1px solid #ccc; padding: 10px; border-radius: 0 5px 5px 5px; } .tab { display: none; } .tab.active { display: block; }
Finally, we will use jQuery to achieve the label switching effect.
$(document).ready(function() { $(".tab-links li").click(function() { var tabId = $(this).find("a").attr("href"); $(".tab").removeClass("active"); $(".tab-links li").removeClass("active"); $(this).addClass("active"); $(tabId).addClass("active"); }); });
Now, we have completed a website with tabs. When we click on different tabs, the corresponding content blocks will be displayed and other content blocks will be hidden. We can add more tags and content blocks according to our needs.
I hope this article will be helpful to you and enable you to easily use HTML, CSS and jQuery to create a website with tabs. If you have any questions, please feel free to ask.
The above is the detailed content of How to make a tabbed website using HTML, CSS and jQuery. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Backdrop-filter is used to apply visual effects to the content behind the elements. 1. Use backdrop-filter:blur(10px) and other syntax to achieve the frosted glass effect; 2. Supports multiple filter functions such as blur, brightness, contrast, etc. and can be superimposed; 3. It is often used in glass card design, and it is necessary to ensure that the elements overlap with the background; 4. Modern browsers have good support, and @supports can be used to provide downgrade solutions; 5. Avoid excessive blur values and frequent redrawing to optimize performance. This attribute only takes effect when there is content behind the elements.

User agent stylesheets are the default CSS styles that browsers automatically apply to ensure that HTML elements that have not added custom styles are still basic readable. They affect the initial appearance of the page, but there are differences between browsers, which may lead to inconsistent display. Developers often solve this problem by resetting or standardizing styles. Use the Developer Tools' Compute or Style panel to view the default styles. Common coverage operations include clearing inner and outer margins, modifying link underscores, adjusting title sizes and unifying button styles. Understanding user agent styles can help improve cross-browser consistency and enable precise layout control.

Define@keyframesbouncewith0%,100%attranslateY(0)and50%attranslateY(-20px)tocreateabasicbounce.2.Applytheanimationtoanelementusinganimation:bounce0.6sease-in-outinfiniteforsmooth,continuousmotion.3.Forrealism,use@keyframesrealistic-bouncewithscale(1.1

Usetheelementwithinatagtocreateasemanticsearchfield.2.Includeaforaccessibility,settheform'sactionandmethod="get"attributestosenddatatoasearchendpointwithashareableURL.3.Addname="q"todefinethequeryparameter,useplaceholdertoguideuse

rel="stylesheet"linksCSSfilesforstylingthepage;2.rel="preload"hintstopreloadcriticalresourcesforperformance;3.rel="icon"setsthewebsite’sfavicon;4.rel="alternate"providesalternateversionslikeRSSorprint;5.rel=&qu

ThetargetattributeinanHTMLanchortagspecifieswheretoopenthelinkeddocument.1._selfopensthelinkinthesametab(default).2._blankopensthelinkinanewtaborwindow.3._parentopensthelinkintheparentframe.4._topopensthelinkinthefullwindowbody,removingframes.Forexte

Use elements and set the action and method attributes to specify the data submission address and method; 2. Add input fields with name attribute to ensure that the data can be recognized by the server; 3. Use or create a submission button, and after clicking, the browser will send the form data to the specified URL, which will be processed by the backend to complete the data submission.

Using tags is the easiest and recommended method. The syntax is suitable for modern browsers to embed PDF directly; 2. Using tags can provide better control and backup content support, syntax is, and provides download links in tags as backup solutions when they are not supported; 3. It can be embedded through Google DocsViewer, but it is not recommended to use widely due to privacy and performance issues; 4. In order to improve the user experience, appropriate heights should be set, responsive sizes (such as height: 80vh) and PDF download links should be provided so that users can download and view them themselves.
