I’m having trouble left aligning a related links div inside a block of text, exactly 250 pixels from the top of a content area, while retaining word wrapping. I attempted to do this with absolute positioning, but the text in the content area doesn’t wrap around the content.
I would just fix the related links div in the content, however, this will display on an article page, so I would like for it to be done without placing it in a specific location in the content.
Is this possible? If so, can someone help me out with the CSS for this?
Example image of desired look & feel…
UPDATE: For simplicity, I’ve added example code. You can view this here: http://www.focusontheclouds.com/files/example.html.
Example HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example Page</title>
<style>
body {
width: 400px;
font-family: Arial, sans-serif;
}
h1 {
font-family: Georgia, serif;
font-weight: normal;
}
.relatedLinks {
position: relative;
width: 150px;
text-align: center;
background: #f00;
height: 300px;
float: left;
margin: 0 10px 10px 0;
}
</style>
</head>
<body>
<div class="relatedLinks"><h1>Related Links</h1></div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tempus est luctus ante auctor et ullamcorper metus ullamcorper. Vestibulum molestie, lectus sed luctus egestas, dolor ipsum aliquet orci, ac bibendum quam elit blandit nulla.</p>
<p>In sit amet sagittis urna. In fermentum enim et lectus consequat a congue elit porta. Pellentesque nisl quam, elementum vitae elementum et, facilisis quis velit. Nam odio neque, viverra in consectetur at, mollis eu mi. Etiam tempor odio vitae ligula ultrices mollis. </p>
<p>Donec eget ligula id augue pulvinar lobortis. Mauris tincidunt suscipit felis, eget eleifend lectus molestie in. Donec et massa arcu. Aenean eleifend nulla at odio adipiscing quis interdum arcu dictum. Fusce tellus dolor, tempor ut blandit a, dapibus ac ante. Nulla eget ligula at turpis consequat accumsan egestas nec purus. Nullam sit amet turpis ac lacus tincidunt hendrerit. Nulla iaculis mauris sed enim ornare molestie. </p>
<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas non purus diam. Suspendisse iaculis tincidunt tempor. Suspendisse ut pretium lectus. Maecenas id est dui.</p>
<p>Nunc pretium ipsum id libero rhoncus varius. Duis imperdiet elit ut turpis porta pharetra. Nulla vel dui vitae ipsum sollicitudin varius. Duis sagittis elit felis, quis interdum odio. </p>
<p>Morbi imperdiet volutpat sodales. Aenean non euismod est. Cras ultricies felis non tortor congue ultrices. Proin quis enim arcu. Cras mattis sagittis erat, elementum bibendum ipsum imperdiet eu. Morbi fringilla ullamcorper elementum. Vestibulum semper dui non elit luctus quis accumsan ante scelerisque.</p>
</body>
</html>
UPDATE2:
Spoke too soon. browsershots.org shows that it barfs on Opera 5 (I used an earlier version) and some editions of Safari, and (of course) IE7 and below (IE8 is OK).
UPDATE:
The following code, shamelessly tweaked from Dan M’s answer, seems to work in modern browsers.
Old Answer:
This may not be possible with just CSS. Consider this page:
Notice that the float handles correctly next to the sidebar and below it (All bets are off in IE6).
But the left margin is wrong for the text above the sidebar — not counting the first paragraph.
That first paragraph appears before the sidebar in the html code. Not only that, but it bumps the sidebar down — it’s no longer at 250px.
I’m pretty sure I can use javascript to fudge around this — after the page is loaded — but I’m NOT recommending that approach.