مشخصات مقاله
ساخت سربرگ برای تب در وب سایت
در این مقاله می آموزیم که چطور با استفاده از CSS و جاوا اسکریپت، Tab headers (سربرگ های tab) ایجاد کنیم.
ساخت tab headerهای قابل تغییر در وبسایت
قدم اول : کد HTML را اضافه کنید.
مثال :
London
London is the capital city of England.
Paris
Paris is the capital of France.
Tokyo
Tokyo is the capital of Japan.
Oslo
Oslo is the capital of Norway.
دکمه هایی ایجاد کنید تا با استفاده از آنها بتوانید محتویات tab خاصی را باز کنید. تمام مولفه های با class="tabcontent" بصورت پیش فرض محو هستند ( با استفاده از CSS و Javascript). زمانیکه کاربر روی دکمه کلیک می کند محتویات tab ای باز می شود که مربوط به همان دکمه می باشد.
قدم دوم : کد CSS اضافه کنید. دکمه ها و محتویات tab را نگارش کنید.
مثال :
/* Style the tab buttons */ .tablink { background-color: #555; color: white; float: left; border: none; outline: none; cursor: pointer; padding: 14px 16px; font-size: 17px; width: 25%; } /* Change background color of buttons on hover */ .tablink:hover { background-color: #777; } /* Set default styles for tab content */ .tabcontent { color: white; display: none; padding: 50px; text-align: center; } /* Style each tab content individually */ #London {background-color:red;} #Paris {background-color:green;} #Tokyo {background-color:blue;} #Oslo {background-color:orange;}
قدم سوم : در پایان نیز کد جاوا اسکریپت را اضافه کنید.
مثال ساخت سربرگ برای تب :
function openCity(cityName, elmnt, color) {
// Hide all elements with class="tabcontent" by default */
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Remove the background color of all tablinks/buttons
tablinks = document.getElementsByClassName("tablink");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].style.backgroundColor = "";
}
// Show the specific tab content
document.getElementById(cityName).style.display = "block";
// Add the specific color to the button used to open the tab content
elmnt.style.backgroundColor = color;
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();

توجه : بخش ساخت تب در وبسایت را مطالعه کنید.