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

Incorporating a variety of images into this hexagonal design framework

Hello there! I am just starting to learn CSS and HTML, and I have a question. Is it possible for me to use the same CSS styling but have different images inside each of the hexagons? I want to replace the image '' with multiple images without rep ...

Modifying the innerHTML of SimpleModal and passing a parameter to a function causes an error to occur

I am currently working on a project where I have a collection of photos displayed on the index page. Each photo should trigger a modal that displays a larger version when clicked. However, I encountered an issue while attempting to use jQuery to modify the ...

Does Google Chrome have a strange way of interpreting CSS?

Almost done with my website and it looks great on Firefox and IE 8, but Chrome is causing issues. Here's how it appears on FF: And here's Chrome: Notice how Chrome resizes the first image even though the code is the same as the one below? Che ...

Exploring the Possibilities of Parsing XML using JSONP

I've checked out a few solutions to similar issues posted here, and I've read through them all! The problem I'm encountering is that I can't seem to make the TfL cycle hire feed work with JSONP. When I try, it returns a 404 error, even ...

Styling elements with CSS to display inline blocks next to each other while taking up the full

I am facing a challenge with two text blocks of varying lengths. The left block contains short text while the right block may have lengthy content. Both blocks need to be displayed side by side, occupying 100% of the parent's width exactly. For a sim ...

Center the cropped image within a div container

Is there a way to set a maximum height for a div containing an image and hide the parts of the image that exceed this height, while keeping it centered vertically inside the div? For example, if the browser width is 1200px and the image aspect ratio is 4:3 ...

What is the best way to ensure my image adjusts its width and height responsively?

How can I make my image responsive to the size of the container, adjusting not just the width but also the height to fit in a container with a max-width of 1300px? I have created a test image with dimensions of 400px height and 1300px width. Take a look a ...

Animate content to slide down using jQuery ajax once it has finished loading

Within my webpage, I have a grid of thumbnails that are each linked to their respective post pages. Upon clicking a thumbnail, a container div below smoothly slides down and loads the content using ajax. An issue has arisen: when I click on a thumbnail fo ...

Troubleshoot the reason behind the malfunctioning Console log on the website

I have been troubleshooting why console.log is not printing anything. I have tried defining and enabling debugger mode, but nothing seems to work. Check out the website here: Any suggestions on how I can resolve this issue? ...

Tips for wrapping text labels in mat-slide-toggles (Angular Material)

Is there a way to get the title in mat-slide-toggle to wrap if it's too long while keeping its default position to the right of the toggle? <mat-slide-toggle class="slider">A really long title wrapped</mat-slide-toggle> I attemp ...

Using a SASS watcher to keep an eye on every folder and compile them into a single CSS

I'm interested in setting up a folder structure like this: assets - scss - folder file.scss anotherfile.scss anotherfile.scss anotherfile.scss - anotherfolder file.scss anotherfile.scss anotherfile.scss ...

The lack of vertical alignment in the table

Trying to do something really simple here and I'm a bit stuck. Currently working on a forum project, and surprisingly the backend is error-free (thanks to some questionable magic tricks), However, my current task is to display all subcategories using ...

iOS experiences a lag in loading dynamic images

I have created a unique jquery carousel specifically designed for mobile devices. It features three containers that display three images at a time, with jquery handling the animation. By detecting the user's swipe direction (left or right), I update t ...

When navigating to a different page in Chrome, the Html5 audio player unexpectedly halts playback of the

During my ASP.NET MVC project, I integrated an HTML5 audio player. However, I noticed that when switching to another page, the player paused or stopped playing in Chrome but continued in Firefox as I had saved the player content in a hidden field. Is there ...

What is the best way to update the color CSS property of an element with jQuery?

Can someone explain to me how to modify CSS using jQuery? I am trying to change the font color of "Valid VIN" to red, but my current code doesn't seem to be working: $("#result").html(<font color="red">"Valid VIN"</font>); ...

Building a basic music player with the <audio> element and JavaScript / jQuery

I am new to Javascript and jQuery, and this is my first time posting a question here. I have been trying to create custom functions for the HTML5 audio tag by following tutorials online. Despite my efforts, I cannot seem to get it working. Although I can m ...

Tips for Creating an Animated Progress Bar in a Slider

After implementing jQuery, I managed to create a unique slider on my website. This slider included a thumbnail with captions for each photo. Positioned below the thumbnail was a progress bar fixed in the center between the caption and the image. Users can ...

What is the best way to format a time in a 12-hour clock using JavaScript?

Is it possible to create a timer that performs an action after 12 hours? I want the timer to start at 6am and end at 6pm, lasting for exactly 12 hours. Additionally, I'm interested in converting my current 12-hour clock into a 24-hour format. I am se ...

Using a percentage width on a <div> element with the "overflow-x: scroll" property does not seem to be functioning properly, even when encapsulated within

My code includes a div within another div, taking up 50% of the page's width: <div id="mainContainer" class="mainContainer"> <div id="scroller" class="scrolling"> <!-- items here should make the div really long --> & ...

Resizing cell height in an HTML table is not supported by Angular 5

In my angular application, I've implemented a component that represents a basic HTML table. However, I'm facing an issue with reducing the height of cells within the table. It seems like my CSS styling is not affecting the display as desired. He ...