I’m new to CSS, and I’ve looked for help in the previous forums on this issue. I think I’m doing everything right but my floated elements are being yanked to the left.
Here is my code:
div {
display: block;
}
.grid {
width: 660px;
position: relative;
float: left;
padding-bottom: 10px;
clear: left;
}
.home {
text-align: center;
float: left;
width: 33.3333333%;
position: relative;
padding: 25px;
}
.third {
display: inline-block;
position: relative;
float: left;
height: 150px;
width: 150px;
border-radius: 25px;
}
.third img {
float: left;
position: relative;
}
And my html:
<div class="grid">
<article class="home">
<article class="third">
<img src="" /></article>
</article>
<article class="home">
<article class="third">
<img src="" /></article>
</article>
<article class="home">
<article class="third">
<img src="" /></article>
</article>
</div>
Help please!
I can’t comment yetâ¦
Your original code on fiddle
The problem come from
padding
in.home
class.I have disabled
padding:25px;
here in.home
class, becausepadding
is added towidth
in CSS:The modified version (without padding) on fiddle
Now it’s not “pulled too far on the left“.
What you can do instead, is to add
margin:25px;
to.third
class, like this:The modified version (with margin) on fiddle
EDIT: A CLEAN REVISITED VERSION:
The HTML code:
The CSS code:
The result here on fiddle.
Images are adaptative, centered vertically and horizontally.
The
.third
class have a light grey background color just for testing and displaying the curved borders and the centered images inside it.I have also replaced in html code, the second
<article>
tag by a<div>
tag, because it is redundant.Please use the updated code I think it will work.
Here’s a possible correction of your code to you :
See this fiddle
I’ve changed a little the HTML structure like this :
It’s better for semantic to have
section
aroundarticle
and notarticle
aroundarticle
.I’ve simplify the CSS code like this :
If you use fluid
width
for container, then use fluidwidth
forpadding/margin
of article.In that case, i use fixed
width
of the container and forpadding
values.