c.telarico
15 Jan 2008, 03:47 PM
Consider the following HTML:
<head>
<style>
#chapter {
margin-left:40px;
}
p {
margin-bottom: 2em;
}
.comment {
position: relative;
left: -25px;
}
.number {
position: absolute;
}
</style>
</head>
<body>
<div id="chapter">
<p>
paragraph one
</p>
<div class="comment"><span class="number">4</span></div>
<p>
paragraph two
</p>
</div>
</body>
This will display two paragraphs of text, and the number '4' will appear 25px to the left of the first line of the second paragraph, which is what I want. Now, remove the "position:absolute" style from the span, and the display is totally different, the second paragraph is pushed down the page and displays a full 2ems below the number.
Why does the positioning of the span inside the div change this? I would really like to understand this.
-ct
<head>
<style>
#chapter {
margin-left:40px;
}
p {
margin-bottom: 2em;
}
.comment {
position: relative;
left: -25px;
}
.number {
position: absolute;
}
</style>
</head>
<body>
<div id="chapter">
<p>
paragraph one
</p>
<div class="comment"><span class="number">4</span></div>
<p>
paragraph two
</p>
</div>
</body>
This will display two paragraphs of text, and the number '4' will appear 25px to the left of the first line of the second paragraph, which is what I want. Now, remove the "position:absolute" style from the span, and the display is totally different, the second paragraph is pushed down the page and displays a full 2ems below the number.
Why does the positioning of the span inside the div change this? I would really like to understand this.
-ct