css Problems with the height of the tab bar

Trying to set up a tab bar with additional padding on hover, but encountering an issue where the parent div moves on hover state.

Here is the HTML code:


    <div id="statNav">
        <a href="#">Gogus</a>
        <a href="#">Kol</a>
        <a href="#">Gogus</a>
        <a href="#">Gogus</a>
        <a href="#">Gogus</a>
        <a href="#">Omuz</a>
        <a href="#">Gogus</a>
    </div>

And the CSS code:


    #statNav{
        width:100%;
        border-bottom:2px solid #9B2F2C;
        overflow:auto;
    }

    #statNav a{
        float:left;
        background-color:#333333;
        color:white;
        font-size:12px;
        font-weight:bold;
        text-align:center;
        width:62px;
        padding-top: 5px;
        padding-bottom:5px;
        border-right: 1px solid #777777;
    }

    #statNav a:first-child{
        -webkit-border-radius: 5px 0px 0px 0px;
        border-radius: 5px 0px 0px 0px;
    }

    #statNav a:last-child{
        -webkit-border-radius: 0px 5px 0px 0px;
        border-radius: 0px 5px 0px 0px;
        border-right:none;
        width:63px;
    }

    #statNav a:hover{
        -webkit-border-radius: 5px 5px 0px 0px;
        border-radius: 5px 5px 0px 0px;
        background-color:#9B2F2C;
        padding-top: 15px;
    }

View the working sample here.

Any suggestions on how to fix this issue?

Answer №1

To tackle this issue, consider implementing margins on the tabs that are not being hovered over, then removing them when the user hovers over them to compensate for the larger padding size. Remember to set the margin size to match the difference between the padding sizes for the hovered and non-hovered states.

#tabMenu a{
    margin-bottom: 15px;
    padding-bottom: 10px;
}
#tabMenu a:hover{
    margin-bottom: 0;
    padding-bottom: 20px;
}

Check out the updated jsFiddle link for a demonstration of this workaround.

Answer №2

To adjust the hover effect, you can tweak it by applying a negative margin-bottom that equals the difference in padding. Here's an example of how you can do this:

#statNav a:hover{

    -webkit-border-radius: 5px 5px 0px 0px;
    border-radius: 5px 5px 0px 0px;
    background-color:#9B2F2C;
    padding-top: 10px;
    margin-bottom: -5px;
}

Check out this JSFiddle link for a live example.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

One of the unique CSS properties found in the NextJS setup is the default 'zoom' property set to

Even though I already found a solution to the problem, I can't help but wonder what the author meant by it. Hopefully, my solution can help others who may encounter the same issue. After installing the latest NextJS version 13.2.4 on my computer, I e ...

Concealing items in a loop using Javascript

I need assistance with this issue. I am trying to hide text by clicking on a link, but it doesn't seem to be working correctly. Even though I tried the following code, I can't figure out why it's not functioning as expected. Is there a diff ...

Using inline-block can be effective on certain occasions

Hi everyone, I'm currently facing a puzzling issue and not sure what's causing it. Sometimes the elements I've set as inline-blocks cooperate as expected, but then when I refresh the browser, they suddenly decide to misbehave. Below is my ...

Crystal Reports does not recognize or integrate HTML elements

Despite entering HTML text on the field: https://i.sstatic.net/vyvQ2.png Even though I am using valid tags as explained in this resource: What HTML tags are supported in Crystal Reports 2008, my report is not generating HTML but only displaying the tags ...

Expanding the width of a Datatables within a Bootstrap modal

While working on my modal, I encountered an issue with the width of Datatables. Despite trying to adjust it to fit the modal size, it appears like this: https://i.sstatic.net/bLvIJ.png Below is the jQuery code calling the Datatables: function retrieveTa ...

What is the process for transferring selections between two select elements in aurelia?

I am attempting to transfer certain choices from select1 to select2 when a button is clicked. Below is my HTML code: <p> <select id="select1" size="10" style="width: 25%" multiple> <option value="purple">Purple</option> &l ...

Struggling to display the Three.js LightMap?

I'm having trouble getting the lightMap to show on my mesh. Here's the code I'm using: loader.load('model.ctm', function (geometry) { var lm = THREE.ImageUtils.loadTexture('lm.jpg'); var m = THREE.ImageUtils.loadT ...

JavaScript not functional, database being updated through AJAX calls

I have created a game using Phaser, a JavaScript library for games. Now I am looking to implement a score table using JS/PHP. My main focus is on transferring a variable from JS to PHP in order to update the database. I have researched numerous topics and ...

Center align a font-awesome icon vertically next to a paragraph of text

Is there a way to align a font-awesome icon on the left side of a text paragraph while keeping the text on the right side, even if it's longer and wraps underneath the icon? I've tried various code snippets but haven't found a solution yet. ...

Use jQuery ajax to send form data and display the received information in a separate div

I'm working on a PHP test page where I need to submit a form with radios and checkboxes to process.php. The result should be displayed in #content_result on the same page without refreshing it. I attempted to use jQuery Ajax for this purpose, but noth ...

Is it possible to change the button class within a div while ensuring only the last one retains the change?

Here is a code snippet I'm using to switch between classes for buttons: $('button').on('click', function(){ var btn=$(this); if(btn.attr('class')=='tct-button'){ btn.removeClass('tct-button ...

Position a div in the center of the page horizontally

Can someone help me with aligning the #main div in the center of the page? I have this code snippet: <div id="main" style=" margin:0 auto; "> <div style="float: left"> <a style="display: block" href="#"><img src="test.gif" ...

``Inconvenience of Extensive URLs Being Displayed in Tables

I've been struggling to find a solution for the problem I'm facing with Chrome when it comes to wrapping long URLs in a table cell. Despite trying various solutions found online, including using the CSS code word-wrap: break-word;, I have not bee ...

Looking to transform a list into JSON format using JavaScript?

I have a collection that looks like this: <ol class="BasketballPlayers"> <li id="1">Player: LeBron, TotalPoints: 28753, MVP: true</li> <li id="2">Player: Steph, TotalPoints: 17670, MVP: true< ...

How to Add Catchy Titles to Your Menu Items on Silverstripe CMS?

Hey there! I'm currently working with Silverstripe CMS using the "Simple" template. I'm interested in finding out how to add subtitles to my menu items. Here's the current structure of my navigation template: <nav class="primary"> &l ...

Wordpress Debacle: Bootstrap Columns Clash

Currently, I am in the process of designing a unique theme. In my code, I have implemented a condition that generates an additional div with the class "row" after every three posts or columns are created. Everything seems to be working smoothly, except f ...

Ways to delete an image from a batch file uploading feature

I encountered an issue with my multiple image upload function that includes preview and remove options. When I select 4 images and preview them correctly, removing 2 from the preview still results in uploading all 4 images to the database. $(document).rea ...

Concealing the ellipsis in the will_paginate function of Rails

I'm currently utilizing will_paginate to manage a large number of values, but I am struggling to find a way to hide the "..." portion and the page numbers following it. Here is my current setup: https://i.stack.imgur.com/f2Tt8.jpg However, what I wou ...

Emphasize Expandable Sections based on Search Term

I have been working on developing an HTML page for my company that will showcase a list of contacts in an "experts list". Currently, the list is structured using collapsible DIVs nested within each other. Additionally, the HTML page features a search func ...

Access an image URL that is saved in a MySQL database

Currently, I am facing a challenge attempting to populate an img tag src attribute with a filename sourced from a mysql database. As of now, I retrieve two images through a single MySQL query (selected randomly). However, in the future, I anticipate needi ...