I would like to see Sniperman's results.
To me "FLOAT" (compared to "align") is a sloppy aspect of CSS. I know floated element has to have a width, the parent element of floated elements should also be floated, other elements should wrap around floated/aligned elements, etc. But, for the life of me, I cannot visualize floating an element with position: absolute (which takes element out of normal HTML flow of document). See attached screen shot (the code of which is below).
Code:
<div style="position:relative; margin: 20px auto;">
<p style="background: silver; margin: 20px;">I was just curious. I am doing a minor fix with a Twitter widget and externalized the code to clean it up a bit. The widget is wrapped in a DIV and I've placed this DIV underneath the H1 tag and floated it to the right to give it a nice position. The problem is that because the code is in the content section, it can easily be deleted in a HTML editor. So I decided to place the code at the bottom of the content DIV and styled it with </p>
<div style="float:left; width: 300px; position: relative;
padding:5px;margin-top:5px;top:5px;left:5px; border:thick #0C9 inset;">
<h1 style="float:left; width: 95%;">This is relative "parent" FLOATED.</h1>
<div style="float:left; width: 287px; position:absolute;
padding:2px; top:145px; left:8px;
border:thick #0C9 inset; height: 98px;">
<h2 style="float:left; width: 95%;">This is absolute "child"
of relative "parent" FLOATED.</h2>
</div>
</div>
<p style="background: yellow; margin: 20px;">I was just curious. I am doing a minor fix with a Twitter widget and externalized the code to clean it up a bit. The widget is wrapped in a DIV and I've placed this DIV underneath the H1 tag and floated it to the right to give it a nice position. The problem is that because the code is in the content section, it can easily be deleted in a HTML editor. So I decided to place the code at the bottom of the content DIV and styled it with </p>
<div style="float:right; width: 300px; position:absolute; padding: 2px; margin-top:2px; top:10px; right:20px; border:thick #ff0000 inset;">
<h1 style="float:right; width: 95%;">This is absolute "parent" FLOATED.</h1>
<div style="float:right; width: 200px; position:relative;
padding:2px;top:20px; right:30px;
border:thick #ff0000 inset;">
<h2 style="float:right; width: 95%;">Relative "child"
of absolute "parent" FLOATED.</h2>
</div>
</div>
<p style="background: silver; margin: 20px;">I was just curious. I am doing a minor fix with a Twitter widget and externalized the code to clean it up a bit. The widget is wrapped in a DIV and I've placed this DIV underneath the H1 tag and floated it to the right to give it a nice position. The problem is that because the code is in the content section, it can easily be deleted in a HTML editor. So I decided to place the code at the bottom of the content DIV and styled it with </p>
<!--<div style="float:left; width: 300px; position:relative;
padding:10px;top:100px;left:10px; border:thick #ff0000 inset;">
<h1 style="float:left; width: 95%;">This is relative "parent" FLOATED.</h1>
<div style="float:left; width: 200px; position:absolute; padding:10px; margin-top:200px; top:-41px; left:30px; border:thick #ff0000 inset;">
<h2 style="float:left; width: 95%;">This is absolute "child" of relative "parent" FLOATED.</h2>
</div>
</div> -->
<p style="background: yellow;">I was just curious. I am doing a minor fix with a Twitter widget and externalized the code to clean it up a bit. The widget is wrapped in a DIV and I've placed this DIV underneath the H1 tag and floated it to the right to give it a nice position. The problem is that because the code is in the content section, it can easily be deleted in a HTML editor. So I decided to place the code at the bottom of the content DIV and styled it with </p>
<!-- <div style="float:right; width: 300px; position:absolute;
padding:10px;top:50px;right:30px; border:thick #00ff00 outset;">
<h1 style="float:right; width: 95%;">This is absolute "parent" FLOATED.</h1>
<div style="float:right; width: 90%; position:relative;
padding:10px;margin-top:100px;top:60px;right:30px; border:thick #00ff00 outset;">
<h2 style="float:left; width: 95%;">This is relative "child" of absolute "parent" FLOATED.</h2>
</div>
</div> -->
<p style="background: #6FF;">I was just curious. I am doing a minor fix with a Twitter widget and externalized the code to clean it up a bit. The widget is wrapped in a DIV and I've placed this DIV underneath the H1 tag and floated it to the right to give it a nice position. The problem is that because the code is in the content section, it can easily be deleted in a HTML editor. So I decided to place the code at the bottom of the content DIV and styled it with </p>
</div>
I've been trying to research float/absolute. Here are some of my notes from Eric Meyer's © 2007 book CSS: The Definitive Guide on CSS2:
CSS float property [float: left right none inherit] can be applied to any element. ... In some ways, floated element is removed from normal flow of doc. Although it still affects layout, it almost exists on its own plane. Other elements flow around it. Margins around floated elements do not ;collapse.'
Must declare width for 'non-replaced' floated element or element's width 'will tend toward zero\o.'
Float parent ... "A floated element will adjust to contain any floated descendants."
...
Absolutely positioned element's placement and sizing are related ... [position: absolute; top: 1em; left: 1em; right: 25%; bottom: 10px;]
Because 'replaced' elements (e.g., <img>) have an intrinsic height and width, their positioning rules are different from 'no0-replaced' elements.
Bookmarks