How to customize active tab style in EJ2 JavaScript Tab
4 Sep 20269 minutes to read
You can customize the Tab style by overriding its header and active tab CSS classes. To do this, follow these steps:
- Define an HTML string to add animation and customize the Tab header.
- Pass this HTML string to the
textproperty. - Override the styles using custom CSS classes added to the Tab elements.
You can add a custom class to the Tab component using the
cssClassproperty, which is used to customize the Tab component along with the respective CSS selectors.
//Initialize Tab component
var tabObj = new ej.navigations.Tab({
cssClass: "e-tab-custom-class",
items: [
{
header: { 'text': '<div><div class="e-image e-andrew"></div><div class="e-title fade-in">Andrew</div></div>' },
content: 'Andrew received his BTS commercial in 1974 and a Ph.D. in international marketing from the University of Dallas in 1981.He is fluent in French and Italian and reads German.He joined the company as a sales representative, was promoted to sales manager in January 1992 and to vice president of sales in March 1993.Andrew is a member of the Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers Association.'
},
{
header: { 'text': '<div><div class="e-image e-margaret"></div><div class="e-title fade-in">Margaret</div></div>' },
content: 'Margaret holds a BA in English literature from Concordia College (1958) and an MA from the American Institute of Culinary Arts (1966).She was assigned to the London office temporarily from July through November 1992.'
},
{
header: { 'text': '<div><div class="e-image e-janet"></div><div class="e-title fade-in">Janet</div></div>' },
content: 'Janet has a BS degree in chemistry from Boston College (1984).She has also completed a certificate program in food retailing management.Janet was hired as a sales associate in 1991 and promoted to sales representative in February 1992.'
}
]
});
//Render initialized Tab component
tabObj.appendTo('#element');<!DOCTYPE html><html lang="en"><head>
<title>Essential JS 2 Tab</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Essential JS 2 Tab">
<meta name="author" content="Syncfusion">
<link href="https://cdn.syncfusion.com/ej2/34.2.2/bootstrap5.3.css" rel="stylesheet">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/34.2.2/dist/ej2.min.js" type="text/javascript"></script>
<style>
.e-content .e-item {
font-size: 12px;
margin: 10px;
text-align: justify;
}
.container {
min-width: 350px;
max-width: 500px;
margin: 0 auto;
}
.e-image {
background-size: 33px;
width: 33px;
height: 30px;
margin: 0 auto;
}
.e-tab-text .e-andrew {
background-image: url(https://ej2.syncfusion.com/javascript/demos/src/tab/images/8.png);
}
.e-tab-text .e-margaret {
background-image: url(https://ej2.syncfusion.com/javascript/demos/src/tab/images/1.png);
}
.e-tab-text .e-janet {
background-image: url(https://ej2.syncfusion.com/javascript/demos/src/tab/images/2.png);
}
.e-tab .e-toolbar-item .e-title {
display: none;
}
.e-toolbar .e-toolbar-items .e-toolbar-item:not(.e-separator),
.e-toolbar .e-toolbar-items .e-toolbar-item .e-tab-wrap {
width: 105px;
height: 50px;
}
.e-tab .e-tab-header .e-toolbar-items .e-active .e-tab-wrap {
background-color: #08c;
}
.e-tab .e-tab-header {
background-color: #e6e6e6;
}
.e-tab .e-tab-header .e-toolbar-item:not(.e-active) .e-tab-wrap:hover {
background-color: #f2f2f2;
color: #000;
}
.e-tab .e-toolbar .e-toolbar-items .e-toolbar-item .e-text-wrap {
height: 50px;
}
.e-tab .e-toolbar-items .e-active .e-image {
display: none;
}
.e-tab .e-toolbar-items .e-active .e-title {
display: block;
color: white;
}
.e-tab .e-toolbar-item .e-text-wrap,
.e-tab .e-toolbar-item .e-tab-text {
width: inherit;
text-align: center;
}
.fade-in {
opacity: 1;
animation-name: fadeInOpacity;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-duration: 0.5s;
}
@keyframes fadeInOpacity {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
</style>
</head>
<body>
<div id="container">
<div id="element"></div>
<br><br>
<div id="result"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>