Internet Explorer is automatically inserting extra vertical space after the first list item in a basic menu design

Does anyone else have trouble with IE? (Or is it just me?)

I'm creating a list with a background. The first and last LI elements are 5px high, while the others are 16px high.

However, in IE there's a strange blank space between the first and second LI elements. Firefox and Safari display it correctly though.

I've tried several solutions but nothing seems to work. I'm stumped...

Below is my CSS:

ul {
    list-style:none;
    margin:40px;
}
li {
    padding:0px;
    margin:0px;
    width:137px;
    height:0px;
    padding-left:10px;
}
.li_norm {
    height:16px;
    background:url(images/modele/li_norm.gif) no-repeat;
}
.li_over {
    color:#ffffff;
    font-weight:bold;
    height:16px;
    background:url(images/modele/li_over.gif) no-repeat;
}
.li_haut {
    height:5px;
    background:url(images/modele/li_haut.gif) no-repeat;
}
.li_bas {
    height:5px;
    background:url(images/modele/li_bas.gif) no-repeat;
}

And here's my jQuery code:

$("#conteneur").append('<ul />');
$("#conteneur ul").append('<li class="li_haut"></li>');
var a= ["Essai 1", "Essai 2", "Essai 3"];
for (var i = 0, j = a.length; i < j; i++) {
    $("#conteneur ul").append('<li id="new_'+i+'" class="li_norm">'+a[i]+'</li>');
}
$("#conteneur ul").append('<li class="li_bas"></li>');

The issue can be seen in this picture:

Strange spacing in IE with LI

Any help would be greatly appreciated.

Asterix93

Answer №1

Consider adding a spacer gif or adjusting the line-height of an empty li element with a height of 5px to fix the gap in IE. The IE Developer tools might indicate that the first LI is causing this issue.

An alternative approach could be applying the top style to the UL background instead of inserting an empty LI. Another suggestion is to use the container's image as a background and set the UL background as the bottom to avoid extra LIs.

Instead of repeatedly using $("#conteneur ul"), storing it in a variable can help minimize lookups throughout the code.

Answer №2

I'm not certain if this solution will be effective, but you could attempt applying the .li_haut class with overflow:hidden.

.li_haut {
    height:5px;
    overflow:hidden;
    background:url(images/modele/li_haut.gif) no-repeat;
}

Answer №3

Incorporating a CSS reset sheet can be beneficial for setting a uniform style in every project.

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

Transfer both FormData object as well as an extra parameter through an AJAX request

I have successfully sent a FormData object like this: var formData = new FormData(); formData.append('file', this.files[0]); $.ajax({ url: urlUploadProductsFile, type: 'POST', data: formData, cache: false, contentType: f ...

Verify the Existence of a Key in JSON Array

I am attempting to create a validation check to determine the presence of a specific key within a JSON array using jQuery. If this key is found, it indicates that no relevant objects were returned from the server and therefore nothing should be displayed o ...

Navigating through pages without using Javascript

While working on creating page numbers, I stumbled upon this intriguing CodePen: https://codepen.io/p-ziegler/pen/bmdaaN .b, input[type="radio"] { display: inline-block; width: 16px; height: 16px; vertical-align: middle; } .b { back ...

Changing the size of a responsive navigation bar with React and adjusting it based on the window.scrollY position switches between collapsed and un

I'm struggling to create a responsive navbar that automatically adjusts its size once it surpasses the height of the navbar (currently set at 80px). However, when I scroll to around the 80px mark, it starts flickering between the collapsed and expande ...

"What's the best way to make sure a checkbox stays checked and its content remains visible after a

After updating my HTML content, it now consists of a hidden table inside a div with the class "myClass": <div class="myClass" style="display:none"> <table class="table table-hover"> ..... </table> </div> The table remains hidden u ...

Is it possible to align the last item in a MUI stack to the bottom?

https://i.stack.imgur.com/IsutM.png Currently, I am working on a modal component using MUI's Grid. My goal is to position the Button at the bottom of the modal. const styles = { modalBox: { position: 'absolute', top: &ap ...

What steps should be taken to resolve the undefined index error in the context of using Jquery Ajax with PHP

Currently, I am utilizing Jquery, Ajax, and PHP in an attempt to send a variable for writing into a MySQL database. Although the Ajax request is being initiated, the PHP script seems unable to pick up the variable. The reason behind this issue remains uncl ...

Ways to create a self-contained video viewer

Is it possible to create a self-contained video player similar to jwplayer or the YouTube video player using just HTML, CSS, and JavaScript? I know that I can build a video player by utilizing the video tag along with some custom javascript and css, but ho ...

Is there a way to confirm if all div elements have a designated background color?

I have a scenario where I have dynamically added several divs with a specific class to my webpage. These divs change color when the user hovers over them. I am trying to trigger a specific function once the last div has been set to a particular backgroun ...

How to perfectly position various height <a> elements in a WordPress mega menu

I'm currently working on a WordPress mega menu with four columns, each with a heading or top menu item. The headings should have a gradient border at the bottom and differ in length. However, I'm facing an issue where some headings span two lines ...

Is there a method to preserve the pressed/focused state when moving from one input box to the next?

While creating a form for a client, I encountered a requirement where the input box should change once clicked and retain that change even after it has been filled and the user moves to the next input box. Is there a way to achieve this using only HTML & C ...

How to achieve smooth transitions in CSS3 with dynamic height changes?

Currently, I am in the process of designing a unique layout. The main challenge lies in toggling between two classes for a div element, one of which has a height of 0px. To achieve this, I have successfully utilized CSS3 animations that effectively scale t ...

Searching with Neo4j, Java and the Angular library for accurate

When my web application is opened, it displays a form where users can input a list of comma-separated usernames. The application then queries the neo4j database to fetch information for each username. I am interested in implementing autocomplete functiona ...

The scrolling feature in IE 7 with IE 7 standard does not respond to the jquery scroll event, whereas it functions properly in IE8 and IE

I have included an example below which consists of a terms div that contains some terms and conditions as its content. The checkbox is enabled when the user scrolls to the bottom of the div. However, this functionality seems to be not working properly in I ...

Discover the hexadecimal color code generated from an rgba color

Do you know of a service that can determine the final hexadecimal value of an rgba color? For instance, if my body background-color is set to #FF0000 and my header is positioned over it with a background-color of rgba(0,0,0,.7), how can I find out what the ...

Tips for displaying a close icon after completing a file upload

I need to implement a feature where once a user uploads a file, a cross sign should be enabled on the file. I attempted to use javascript for this functionality, but it seems to not be working as expected. There are more than 8-10 different file types that ...

Avoid auto-scaling of div content

I need the .content within the main container .box to resize proportionally to match the width of the .box exactly, without being smaller. .box { width: 95%; background-color: red; padding: 20px; text-align: center; margin: 55px auto 40px; } . ...

Creating separation between a dropdown menu and its corresponding button

I'm dealing with a situation where I have a button that reveals a hidden droplist upon hover. The problem is that there is no space between the button and the droplist, causing interference with the functionality. My attempt to create some distance b ...

Is it possible to load the response from the $.post function, which contains GIF content, into a JavaScript Image object

How can I preload an image that the server only returns on a POST request? I want to load the image before displaying it. How can I store the result in a JavaScript object? $.post('image.php', {params: complexParamsObject}, function(result) { ...

jQuery not targeting absolute positioned duplicates of the <div>'s

(Please find the code link at the bottom of this question) I have been working on a radial menu for a web project. However, I've encountered an issue that has me stuck for hours now. No matter what I try, I can't seem to get any response from th ...