Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS gaps between image links for no reason

I've been trying to get this horizontal navigation sorted for the past few hours now and nothing is working. I've tried reset.css stylesheets, *{padding: 0; margin: 0) etc. and I still have gaps inbetween my image links.

You see, the navigation is made up of an unordered list of image links displayed inline, but there are gaps in between each image, left, right, top and bottom and I can't see why. It's the same in all browsers.

Here is a link to the page, and so source: Beansheaf Temporary

Link to css: http://pentathlongb-yorkshire.co.uk/tomsmith/Beansheaf/styles/fund2.css

The rest of the site is obviously still not done, it's just the navigation I'm worried about right now.

like image 429
Infiniti Fizz Avatar asked Apr 17 '10 14:04

Infiniti Fizz


People also ask

How do I remove the gap between images in CSS?

To remove the unwanted space between images or similar HTML elements do one of the following: Put all the elements on one line with no spaces between them. Put the closing bracket of the previous element immediately before the next element on the next line. Comment out the end of line marker (carriage return).

Why is there a gap between images in HTML?

99% of the time, this is due to your image not having the proper styling tag. Every time images are used next to each other in the cells of a table – no matter the width or height specifications of the cell – there should be a display block style added. This removes the white gap between images.

Why is there a gap CSS?

The gap property in CSS is a shorthand for row-gap and column-gap , specifying the size of gutters, which is the space between rows and columns within grid, flex, and multi-column layouts. Use the slider in the demo below to see the gap property in action: HTML.


2 Answers

To avoid floating the navigation lis, you've got -at least- two options to remove the spaces between inline elements.

<ul> 
  <li><a href="#"><img src="../hotel.jpg" /></a></li 
  ><li><a href="#"><img src="../foodDrink.jpg" /></a></li
  ><li><a href="#"><img src="../meetingsConferences.jpg" /></a></li>
</ul>

Note that the closing </li> tag is closed on the subsequent line (except for the last one), which is valid and maintains readability (for me, at least).

The other option is slightly messier

<ul> 
  <li><a href="#"><img src="../hotel.jpg" /></a></li><!-- 
  --><li><a href="#"><img src="../foodDrink.jpg" /></a></li><!--
  --><li><a href="#"><img src="../meetingsConferences.jpg" /></a></li>
</ul>

And just uses html comments <!-- ... --> to comment-out the spaces that would otherwise be collapsed into a single space.

I do wish there was some way of specifying (for example):

ul li img {whitespace: none-between; }
like image 70
David Thomas Avatar answered Sep 21 '22 20:09

David Thomas


Another approach, avoiding floats, is to set the font-size on the container to 0, and then re-set it back up for the LIs, like this:

#mainNav
{    font-size: 0}

#mainNav li
{
    display: inline;
    list-style-type: none;
    font-size: 1em
}
like image 25
graphicdivine Avatar answered Sep 17 '22 20:09

graphicdivine