Forum Moderators: not2easy
I have an image. I want some text or another small image to appear to the left of the image, at the top. And some more text (it's an address, made up as a dl, but a couple of test paragraphs should do) to appear at the bottom left of the image, so that regardless of the number of lines in the address, it always pushes to the bottom, flush with the bottom of the image.
And the image may be 200 x 150, or 150 x 200, or slightly different.
Doctype is XHTML Strict.
The markup:
<body>
<div id="mainWrapper">
<div id="leftWrapper">
<div id="leftTop">
<p>test top</p>
</div>
<div id="leftBottom">
<p>test bottom 1</p>
<p>test bottom 2</p>
</div>
</div>
<div id="rightWrapper">
<img src="images/test1.gif" />
</div>
</div>
</body>
-------------
and the CSS:
* {
border: 0;
margin: 0;
padding: 0;
}
body {
text-align: center;
font: 80% Verdana, Arial, Helvetica, sans-serif;
}
#mainWrapper {
width: 400px;
margin: 0 auto;
margin-top: 20px;
text-align: center;
}
#leftWrapper {
float: left;
}
#leftTop {
}
#leftBottom {
vertical-align: bottom; /* I know this doesn't work */
}
#rightWrapper {
float: right;
}
I've tried all sorts of combinations of position: relative, top: 100%, bottom 0 etc, but I'm just floundering!
Any ideas would be greatly appreciated.
#mainWrapper to position: relative; -- it will be the "stage" for the props #leftTop to: position: absolute;
top: 0; -- it will sit 0 pixels from the top edge, relative to its relatively positioned parent #leftBottom to be absolutely positioned, this time with a bottom: 0; #mainWrapper has no children, thus a height of 0 pixels. Clear the float so the parent has height again, I'll show you a simple method but if you have a preferred one (I like :after + zoom personally) go for it.To clear:
Put this
<div> before the ending element for #mainWrapper <div class="clear"> </div> CSS
div.clear { display: block;
clear: both;
visibility: hidden;
height: 1px;
overflow: hidden;
font-size: 1px; } So,
#mainWrapper should be the height of the image in #rightWrapper, and #leftTop and #leftBottom should be sitting at the top and bottom of #mainWrapper respectively. Play around with widths (remembering that the absolute-relatively positioned elements will take up the amount of space available -- it will overlap your float,) and whatever else you think is necessary.
Let us know how you go.
I thought setting the horizontal spacing would be straightforward, but no way.
Margins, padding -- no effect on the absolutely positioned elements.
So I just set a right after the top/bottom. That justifies any content to the right, regardless of its width.
The image doesn't have an absolute position, it can take a right margin.
I started with the separate div.clear to clear, then looked up the :after method. Used that, and it works in the IEs, and I didn't need zoom.
First class.
By the way... the
:after method doesn't work in IE 6 or 7, they don't have support for the pseudoclass. However, the IEs have a funny way of automatically enclosing their floated children as long as the parent has hasLayout triggered. I think hasLayout gets triggered here in this instance at the
position: relative; marker but I forget. You can find this out by getting the Developer toolbar for IE 6 and 7. Inspect the element, and there will be a "property" that says "hasLayout".
Just some info in case you were wondering why the IEs don't work with the
:after pseudoclass at some later stage, when you thought it did before.