Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted May 12, 2023, 5:24 AM EDT
You can use CSS to add a hover effect on the tab element like this
.tab { /* Set the background color and padding for the tab */ background-color: #eee; padding: 10px; /* Add a transition effect to smooth out the hover effect */ transition: background-color 0.3s ease-in-out; } /* Add a hover effect to change the background color of the tab */ .tab:hover { background-color: #ccc; }Deepak RawatRank #646 · 3.7K reputationPosted May 12, 2023, 11:53 AM EDT
Try this code
* {box-sizing: border-box} body {font-family: "Lato", sans-serif;} /* Style the tab */ .tab { float: left; border: 1px solid #ccc; background-color: #f1f1f1; width: 30%; height: 300px; } /* Style the buttons inside the tab */ .tab button { display: block; background-color: inherit; color: black; padding: 22px 16px; width: 100%; border: none; outline: none; text-align: left; cursor: pointer; font-size: 17px; } /* Change background color of buttons on hover */ .tab button:hover { background-color: #ddd; } /* Create an active/current "tab button" class */ .tab button.active { background-color: #ccc; } /* Style the tab content */ .tabcontent { float: left; padding: 0px 12px; border: 1px solid #ccc; width: 70%; border-left: none; height: 300px; display: none; } /* Clear floats after the tab */ .clearfix::after { content: ""; clear: both; display: table; } Hover Tabs Move the mouse over a button inside the tabbed menu: London Paris Tokyo London London is the capital city of England. Paris Paris is the capital of France. Tokyo Tokyo is the capital of Japan. function openCity(evt, cityName) { var i, tabcontent, tablinks; tabcontent = document.getElementsByClassName("tabcontent"); for (i = 0; iTuhin PaulRank #7 · 71.9K reputationPosted May 12, 2023, 2:46 PM EDT
the code for a hovering effect in CSS that will work on a tab:
.tab {
/* Set the default style for the tab */
}
.tab:hover {
/* Set the style for the tab when the mouse is hovered over it */
}
For example, you could use the following code to change the background color of the tab when the mouse is hovered over it:
.tab {
background-color: #ccc;
}
.tab:hover {
background-color: #fff;
}
You can also use the transition property to animate the change in style when the mouse is hovered over the tab. For example, the following code will animate the change in background color over a period of 0.5 seconds:
.tab {
background-color: #ccc;
}
.tab:hover {
background-color: #fff;
transition: background-color 0.5s;
}
You can also use the transform property to change the size or position of the tab when the mouse is hovered over it. For example, the following code will scale the tab up by 10% when the mouse is hovered over it:
.tab {
transform: scale(1);
}
.tab:hover {
transform: scale(1.1);
}
You can use the :hover pseudo-class to style any element when the mouse is hovered over it. This is a very powerful technique that can be used to add interactivity to your web pages.
Tuhin PaulRank #7 · 71.9K reputationPosted May 12, 2023, 10:05 PM EDT
You can add the following property to the .tab class to create a transition effect when the background color changes
.tab { ... transition: background-color 0.3s ease-in-out; }This will create a transition effect that lasts for 0.3 seconds and has an ease-in-out timing function. You can adjust the duration and timing function to achieve the desired effect.