I have a div containing a floating image and a flanked text. If image is floated to left text is flanked right, if image is floated to right text is flanked left. To display everything fine I've put the img
element before the text and used the +
selector in CSS to give a proper margin to text (see code below).
For small screens, I would like to display text and image as blocks (100% width), with image placed below text. I've tried to use absolute positioning as suggested here, but it didn't work: image is always displayed above. How can I accomplish my goal? Thanks in advance.
HTML
<div class="wrapper">
<img class="sectionimage left" src="image.jpg" />
<div class="sectiontext"> <p>Some text.</p> </div>
</div>
CSS
.wrapper {
overflow:hidden;
}
.sectionimage { /* must always be before text, even if floated right */
vertical-align:bottom;
max-width:400px;
}
.left {
float:left;
}
.right {
float:right;
}
.left + .sectiontext {
margin-left:500px; /* left margin for text after a "left" image */
}
.right + .sectiontext {
margin-right:500px; /* right margin for text after a "right" image */
}
/* images and text displayed as blocks */
@media only screen and (max-width:950px)
{
.sectionimage, .sectiontext {
display:block;
width:100%;
}
.sectionimage {
float:none;
}
.sectiontext {
margin:0px !important;
}
}