I'm trying to display an image and some text on my webpage floating next to each other as you can see below.
I've tried basically all the methods suggested in these two previous SO questions I found on this topic:
- How to display items side-by-side without using tables?
- HTML Code to put image in left and text in right side of screen with footer below?
However, no matter what combinations I try, this is the result that I obtain:
This is the HTML
code for the first example (which seems not to work at all):
<div class="cf">
<img src="//upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Balzac.jpg/220px-Balzac.jpg" width=100>
<div>some text here</div>
</div>
This is the HTML
code for the second example, which differs cause the text is not wrapped into the <div>
container (but seems to work only for a limited amount of text):
<div class="cf">
<img src="//upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Balzac.jpg/220px-Balzac.jpg" width=300>
some text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text heresome text here
</div>
The css
file is from Nicholas Gallagher's micro clearfix:
/**
* For modern browsers
* 1. The space content is one way to avoid an Opera bug when the
* contenteditable attribute is included anywhere else in the document.
* Otherwise it causes space to appear at the top and bottom of elements
* that are clearfixed.
* 2. The use of `table` rather than `block` is only necessary if using
* `:before` to contain the top-margins of child elements.
*/
.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.cf {
*zoom: 1;
}
Can you please tell me what is going wrong and how to fix this?