वर्टिकल टैब मेनू
CSS और JavaScript से वर्टिकल टैब मेनू बनाने का कोड:
उदाहरण
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* { box-sizing: border-box }
.tab {
float: left;
border: 1px solid blue;
background-color: black;
width: 20%;
height: 200px;
}
.tab button {
display: block;
background-color: inherit;
color: white;
padding: 22px 16px;
width: 100%;
border: none;
outline: none;
text-align: left;
cursor: pointer;
transition: 0.3s;
font-size: 17px;
}
.tab button:hover {
background-color: gray;
}
.tab button.active {
background-color: #006400;
}
.demo2 {
float: left;
padding: 0px 10px;
border: 1px solid;
width: 70%;
border-left: none;
height: 200px;
}
</style>
</head>
<body>
<h2>परीक्षा</h2>
<p>निम्न परीक्षा जानकारी है:</p>
<div class="tab">
<button class="demo" onclick="infofunc(event, 'dates')" id="current">परीक्षा तिथियां</button>
<button class="demo" onclick="infofunc(event, 'centre')">परीक्षा केंद्र</button>
</div>
<div id="dates" class="demo2">
<h3>तिथियां</h3>
<p>परीक्षा तिथि 25 मार्च को घोषित होगी।</p>
</div>
<div id="centre" class="demo2">
<h3>केंद्र</h3>
<p>परीक्षा केंद्र 30 मार्च को घोषित होगा।</p>
</div>
<script>
function infofunc(e, info) {
var i, content, links;
content = document.getElementsByClassName("demo2");
for (i = 0; i < content.length; i++) {
content[i].style.display = "none";
}
links = document.getElementsByClassName("demo");
for (i = 0; i < links.length; i++) {
links[i].className = links[i].className.replace(" active", "");
}
document.getElementById(info).style.display = "block";
e.currentTarget.className += " active";
}
document.getElementById("current").click();
</script>
</body>
</html>
आउटपुट
- बाईं ओर: वर्टिकल टैब बटन्स (20% चौड़ाई)
- दाईं ओर: कंटेंट पैनल (70% चौड़ाई)
- प्रारंभ में: "परीक्षा तिथियां" सक्रिय (हरा बैकग्राउंड)
- "परीक्षा केंद्र" क्लिक करने पर: संबंधित कंटेंट दिखता है, बटन हरा होता है
वर्टिकल vs हॉरिजॉन्टल टैब्स
| पहलू | वर्टिकल | हॉरिजॉन्टल |
|---|---|---|
| लेआउट | साइडबार स्टाइल | टॉप बार स्टाइल |
| स्क्रीन उपयोग | चौड़ाई लेता है | ऊंचाई लेता है |
| उपयुक्त | कई टैब्स, डेस्कटॉप | कम टैब्स, मोबाइल |
| स्क्रॉलिंग | साइडबार स्क्रॉल हो सकता है | हॉरिजॉन्टल स्क्रॉल |
रिस्पॉन्सिव बनाने के लिए
@media (max-width: 768px) {
.tab { width: 100%; height: auto; }
.demo2 { width: 100%; border-left: 1px solid; }
.tab button { width: auto; }
}