0

http://jsfiddle.net/2psu0gs4/

Have a look at the JS fiddle above. There are some ghost margins that I can't get rid of and I don't understand why they're there??

I have tried Margin: 0; but it isnt working?

<help></help>

Any help?

Tom

Tom Walsh
  • 117
  • 1
  • 2
  • 6

3 Answers3

2

You have a few issues that are causing you trouble.

  1. Your anchors are inline elements and therefore respect whitespace (line breaks and spaces) between tags. You could comment between every tag (See https://css-tricks.com/fighting-the-space-between-inline-block-elements/), but that's a lot of extra markup and is more of a hack than a solution.

I recommend setting your anchors to display as inline-block so they'll handle margins and padding in the way you would expect them to, and then float them left so they all stack neatly against each other.

  1. By setting your images to max-width:25%, you're drawing them at 1/4 width, but they still reserve 100% of their width (sort of like how position:relative affects blocks) which causes the anchor tags to draw at 500px wide.

To solve this, I moved the max-width:25% style from the img declaration to the a declaration. That left me with 500px wide images overlapping each other, but then I solved that by adding the max-width:100% style to the img declaration.

  1. I couldn't tell you why this is, but I've learned from trying to butt images up against other blocks that by default, images reserve ~3-5px beneath them as part of their height property. To get around this, you can add display:block to your img styles. This causes the image to only reserve the exact width and height the image is drawn at, and because it's wrapped in an inline-block element, it will still stack nicely.

.

.content a {
    display:inline-block;
    margin:0;
    max-width:25%;
    float:left;
}
.content img {
    display:block;
    max-width:100%;
    margin: 0;
    padding: 0;
}

https://jsfiddle.net/2psu0gs4/5/

Bmd
  • 1,308
  • 8
  • 15
0

To get rid of the horizontal invisible margins use float. The vertical margin on the other hand is not a margin, it's space of the element that was not filled by the image (since the image will try to maintain its aspect ratio), if you want to get rid of it you could stretch the image to fill in the gap.

Taking your fiddle as a base, try this:

.content img {
    width:100%;
    height:100%;
}

.content a {
    width:25%;
    height: 100px;
    float: left;
}

http://jsfiddle.net/2psu0gs4/6/

dscastillo171
  • 184
  • 1
  • 4
-1

The spaces and line breaks between your divs in the html markup are responsible for the space between them in display. You have to remove those spaces or simply add html comments <!-- spaces and linebreaks --> like here.

edit by the way - your markup is not valid. The <li> items must be used as direct child of the <ul> - I updated my fiddle accordingly.

dhh
  • 4,289
  • 8
  • 42
  • 59