Reputation: 5779
I have successfully placed an image on the left like so:
<div class="Carl1">
<a href="https://rads.stackoverflow.com/amzn/click/com/1940412145" rel="nofollow noreferrer" target="_blank"><img class="image-left" src="http://caribeauchamp.com/wp-content/uploads/2015/04/first-time-final-cover.jpg" alt="My First Time in Hollywood" />
<span><strong>Amazon</strong></span>
</a>
</div>
And CSS:
.Carl1 {
text-align: left;
}
.image-left {
float: left;
margin: 15px 20px 10px 0px;
border: solid 4px #fff;
}
However my text appears on the upper right of the image when I want it to appear under the image. What am I doing wrong?
Upvotes: 5
Views: 13300
Reputation: 1102
Float needs to be cleared. Also you used span element, what is inline element by the default, you will need to set span element as block element.
Here is a JSfiddle link.
HTML:
<div class="Carl1">
<a href="http://rads.stackoverflow.com/amzn/click/1940412145" target="_blank">
<img width="100" class="image-left" src="http://caribeauchamp.com/wp-content/uploads/2015/04/first-time-final-cover.jpg" alt="My First Time in Hollywood" />
<span class="title"><strong>Amazon</strong></span>
</a>
</div>
CSS:
.Carl1 {
text-align: left;
}
.image-left {
float: left;
margin: 15px 20px 10px 0px;
border: solid 4px #fff;
}
.title {
clear: left;
display:block;
}
Upvotes: 9
Reputation: 16568
Your question indicates you haven't quite figured out how floats work. The answers here will solve your problem today, but I suggest learning more about CSS positioning.
Here is a really great and classic tutorial on the subject. It’s old, but it’s good stuff. You will have a lot easier time with CSS afterwards, I promise.
Also, I’d specifically suggest that you don’t float this image by itself; instead, float the the whole container (.Carl1
) and give it a width
.
Compared to the other answers on this page, this solution is closer to expressing your intention in code. I assume you consider the whole Carl1
div to be essentially one object whose contents should appear together. Floating them as one is true to this intention :)
Upvotes: 3
Reputation: 5468
The float needs to be cleared otherwise the text will attempt to Wrap around the image
.Carl1 span{display:block;clear:both;}
Upvotes: 3