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
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
You have a few issues that are causing you trouble.
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.
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.
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;
}
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;
}
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.