Differences in padding of navigation items between Firefox and Chrome as well as IE11

I am facing an unusual issue with the rendering of a simple navigation/menu. Below is the code snippet:

HTML:

<nav id="navigation">
<ul>
<li class="active"><a  href="http://bybyweb.com/hygeineco/">HOME<br><span>What we do</span></a></li>
<li><a href="http://bybyweb.com/hygeineco/about">ABOUT<br> <span>Our expertise</span></a></li>
<li><a href="http://bybyweb.com/hygeineco/services">SERVICES<br><span>Our products</span></a></li>
<li><a href="http://bybyweb.com/hygeineco/why">WHY CHOOSE US<br><span>Our promise</span></a></li>
<li><a href="http://bybyweb.com/hygeineco/news">NEWS<br><span>Updates</span></a></li>
<li><a href="http://bybyweb.com/hygeineco/charity">OUR CHOSEN CHARITY<br><span>Great Ormond Street</span> </a></li>
 <li><a href="http://bybyweb.com/hygeineco/contact">CONTACT US<br><span>Get in touch</span> </a></li>

</ul>
</nav>

Relevant CSS:

#navigation {
    width:100%;
    clear:both;
    background-color:#a9218e;
    height:72px;

}

#navigation ul {
    width:894px;
    height:72px;
    list-style-type:none;
    margin:0 auto;
    padding:0;
    box-sizing:border-box;
}

#navigation ul li {
    display:block;
    float:left;
    text-align:center;
    padding:10px 22px 0 22px;
    margin:0;
    height:72px;
    box-sizing:border-box;

}
#navigation ul li:last-child {
    padding:10px 20px 0 19px;
}

#navigation ul li a {
    color:#fff;
    text-decoration:none;


    width:100%;
    height:72px;
    font-size:15px;
    font-weight:400;
}

#navigation ul li.active {
    background-color:#00837e;
}

Test link:

Currently, the menu appears perfectly in Firefox fitting the container's size (894px). However, in Chrome and IE11 (and possibly lower versions), one item gets pushed down. It seems like there is not enough space for that particular item (contact) due to the paddings. Adjusting the container width or reducing padding only results in a slight 2px difference between Chrome and Firefox. With a container width of 896px, everything works fine in Chrome, but in IE11, the container width needs to be at least 903px? What could be causing these discrepancies? Perhaps different rendering of the chosen Google font in each browser. How can this issue be resolved?

Answer №1

To implement the box-sizing:border-box property, make sure to include the following code snippet wherever it is required:

box-sizing:border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
-ms-box-sizing:border-box;
-o-box-sizing:border-box;

The prefix -webkit- caters to Safari and Chrome browsers.

-moz- is typically used for Mozilla, although some browsers may interpret the code without it.

-o- is specific for Opera, while -ms- applies to Internet Explorer.

Answer №2

After some trial and error, I found that utilizing display:table for ul and display:table-cell for li elements was the key to almost solving my issue. The only thing left now is to eliminate the margin and padding at the bottom... :)

UPDATE: The background image position was causing a problem, but it's all sorted out now. It seems like good old tables are still the most reliable solution for certain scenarios. :)

UPDATE 2: While I considered removing this question, I believe it might be beneficial to someone facing a similar dilemma. In conclusion -> if you have a menu with varying widths for each item, but need to fit it into a fixed width container, opting for right/left padding on li elements may not be the ideal choice. Displaying them as table and table-cell proves to be the best (and possibly only) route.

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

Choose a HTML element <a> containing a hyperlink reference and a nested child element <li>

Does anyone know of a way in javascript/css to select the (n) <li> in my code, while also specifying that the <li> must have a parent with the current <a> tag containing a specific href link? <a href="www.link.com">CATEGORY NAME& ...

lack of margin space for a specific container

Why is there no space between the two specific divs inside a row? I attempted to add gx-2 to the parent row, but it did not create space between those columns. To see the issue more clearly, run the code snippet on the full page. <link href="https:// ...

I aim to place my :after content in mobile view or lower resolutions

I have a testimonial section built with HTML and CSS. You can view the demo on JSFIDDLE HERE. In the mobile view, I am facing an issue where the ":after" content is not aligning properly or appears misplaced. I'm looking for ideas to ensure that it re ...

Angular animation not firing on exit

I am encountering an issue with my tooltip component's animations. The ":enter" animation is working as expected, but the ":leave" animation never seems to trigger. For reference, here is a link to stackblitz: https://stackblitz.com/edit/building-too ...

Align component within material-ui grid

Looking to center align the same cards but not just the grid component, I need the content itself to be equally distant from the borders and each other. I've searched and tried different solutions without luck. https://i.stack.imgur.com/aZj7H.png htt ...

Achieving vertical center alignment of an element using CSS

I have been attempting to vertically center the content within my div. Here is the HTML code: <div id="header"> <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1" id="logo-img-div"><img id="logo-img" src="logo.png"></div> ...

jQuery/MVC3 script not triggering onclick event after initial execution

Hey there, I'm having an issue with a function that is triggered when clicking on an image. It seems to only be called once even though I expect it to be called multiple times. Here's the JavaScript code, combined with a bit of razor syntax, tha ...

Employing form elements such as checkboxes within a contenteditable div

I'm facing a challenge with placing form elements, specifically simple checkboxes, inside a contenteditable <div />. The issue is that the checkboxes are unresponsive when placed within a contenteditable element - clicking on them or their label ...

Issue with the overall HTML design

The placement of the banner is exactly where I want it to be, however, the boxes using jQuery masonry are overlapping it. I'm not sure what I did wrong here. Any suggestions or insights on how to fix this issue? Example HTML Code: <script type="t ...

Adjust modal size dynamically from the middle with JavaScript and CSS

Take a look at this fiddle example: http://jsfiddle.net/c2mmQ/ In the fiddle, I have implemented a modal using jQuery that fades in and scales up with CSS animations when the show link is clicked. Inside the modal, there is another link that is supposed t ...

Guide to modifying the background image color using CSS

Currently, I am attempting to modify the color of an image using CSS. This particular image is a key element in the layout of my website. To get a better understanding, you can view a screenshot of the element here: , and see an example post containing the ...

Adjusting the width of a <div> element based on window size changes

So I have this Vuejs application that has three divs using CSS grid: a sidebar, a config panel, and a preview. I want to dynamically set the width of the preview div in pixels based on the current screen size and when the screen is resized. To give a bett ...

Using HTML strings in JavaScript code

I am currently working on a basic modal feature where I pass a string to be displayed as the content of the modal window. Here is a snippet of the script I am using: $("[id^='mod_']").click( function() { var line1 = $(this).attr("d ...

Tips for moving objects in both the X and Y directions using only CSS transformations

Is it possible to rotate a card simultaneously in the X and Y directions? I have an image that I would like to rotate in both the X and Y directions! This code is written in HTML, <div class="card"></div> and this is CSS, .card { backgroun ...

Transforming HTML features into PHP scripts. (multiplying two selected values)

I am currently working on converting these JavaScript functions into PHP in order to display the correct results. I need guidance on how to use PHP to multiply the values of the NumA and NumB select options, and then show the discount in the discount input ...

Is there a way to dynamically adjust the overflow-y property based on the height?

Trying to make the overflow-y-visible property visible if the height is too small, otherwise using overflow-y-hidden with tailwind CSS and React. Struggling to achieve this as I can't use sm, md, etc. for height like I can for width. Could someone pl ...

Tips for styling Pandas dataframe using IPython HTML display

Is there a way to customize the display of pandas dataframes in IPython html format? I want to achieve the following: Have numbers right justified Add commas as thousands separators for numbers Show large floats without decimal places I am aware that nu ...

The marquee's position is reset the first time text is loaded dynamically from an API

In my angular project, I'm implementing a marquee feature to display data fetched from an API. However, I've noticed a strange issue where after a page reload, the marquee starts from right to left but once it reaches the end of the div, it reset ...

The swipe function of Hammer.js is unable to detect gestures on a rotated iframe

After creating a rotated iframe on the page using CSS transforms, I attempted to implement swipe events within the iframe. body.rotate iframe { transform: rotate(90deg); transform-origin: top right; position: absolute; t ...

What is the best way to center a div vertically on the page?

I've utilized Bootstrap 3 to create this row: <div class="cart"> <div class="row border"> <div class="col-md-8 desc pad itemsheight"> <div class="col-md-12"> <!-- react-text: 141 -->Docos <!-- /react ...