Reputation: 9408
I have a list of images that I'm trying to move but it isn't working.
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" type="text/css" href="assets/css/style.css" />
</head>
<body>
<div id="wrapper">
<h1>Portfolio</h1>
<img src="assets/img/PHOTOGRAOHY.png" alt="Photography" width="214" height="183">
<img id="industrialDesignIMG" src="assets/img/ID.png" alt="Industrial Design" width="232" height="183">
<img src="assets/img/GraphicDesign.png" alt="Graphic Design" width="233" height="196">
<img src="assets/img/animation.png" alt="Animation" width="198" height="142">
</div>
</body>
</html>
CSS:
#industrialDesignIMG {
border:1px #fff solid;
display: inline-block;
margin-top: 80px;
}
#wrapper {
width:960px;
margin:0 auto;
}
I want #industrialDesignIMG
to have a margin-top
of 80px
, but either nothing moves or all the img
elements move. What can I do to get my margin-top
working?
Upvotes: 0
Views: 8082
Reputation: 2409
The default positioning of any element is static. Hence the ordering/positioning of any element will vary depends on the position of sibling elements.
To be simple, just add CSS float: left
to the image tags and assign margin for your specific image. Example:
#wrapper img { float: left; }
Now add margin to your #industrialImg
. This move your header to corner. Just wrap all the img
with a new div
. That should work.
Upvotes: 0
Reputation: 1621
Images are inline elements. To fix this float each image to the left, this will make it a block element:
img { float: left }
Upvotes: 4
Reputation: 15184
It actually is being applied. It's just that since the images are all inline elements, they're inline with each other, so is appears they're all being shifted down 80 pixels because the images align at the bottom.
See this JSFiddle without the top margin and this JSFiddle with the top margin.
Upvotes: 6