Where did you install Firefox from? Help Mozilla uncover 3rd party websites that offer problematic Firefox installation by taking part in our campaign. There will be swag, and you'll be featured in our blog if you manage to report at least 10 valid reports!

Buscar en Ayuda

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Why is a floating box outside its container?

  • 5 respuestas
  • 1 tiene este problema
  • 2 visitas
  • Última respuesta de cor-el

more options

This code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
><TITLE ></TITLE >
<BLOCKQUOTE STYLE="BACKGROUND: YELLOW; HEIGHT: 10EX" ><P STYLE="FLOAT: RIGHT" >Lorem<HR ><P STYLE="FLOAT: RIGHT" >ipsum</BLOCKQUOTE >
  • Why is BLOCKQUOTE wider than HR?
  • Why is ‘Lorem’ aligned with the widened BLOCKQUOTE?
  • Why is ‘ipsum‘ not aligned likewise?
This code: <pre><nowiki> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ><TITLE ></TITLE > <BLOCKQUOTE STYLE="BACKGROUND: YELLOW; HEIGHT: 10EX" ><P STYLE="FLOAT: RIGHT" >Lorem<HR ><P STYLE="FLOAT: RIGHT" >ipsum</BLOCKQUOTE ></nowiki></pre> * Why is BLOCKQUOTE wider than HR? * Why is ‘Lorem’ aligned with the widened BLOCKQUOTE? * Why is ‘ipsum‘ not aligned likewise?

Modificadas por cor-el el

Solución elegida

To achieve what you want, you have to add some clearing DIV elements or CSS rules.


data:text/html;charset=utf-8,
<!doctype html public "-//w3c//dtd html 4.01//en">
<head> 
 <title></title>
</head> 
<body>
<blockquote style="background: yellow;" >
 <p style="float: right;" >Lorem</p>
 <hr style="clear: both;" >
 <p style="float: right;" >ipsum</p>
 <div style="clear: both;"></div>
</blockquote>
</body>
Leer esta respuesta en su contexto 👍 0

Todas las respuestas (5)

more options

Well, not quite the code I intended…

Maybe this will work:

< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
>< TITLE >< /TITLE >
< BLOCKQUOTE STYLE="BACKGROUND: YELLOW; HEIGHT: 10EX" >< P STYLE="FLOAT: RIGHT" >Lorem< HR >< P STYLE="FLOAT: RIGHT" >ipsum< /BLOCKQUOTE >

Modificadas por cor-el el

more options

Or this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ><TITLE ></TITLE > <BLOCKQUOTE STYLE="BACKGROUND: YELLOW; HEIGHT: 10EX" ><P STYLE="FLOAT: RIGHT" >Lorem<HR ><P STYLE="FLOAT: RIGHT" >ipsum</BLOCKQUOTE >

more options

Solución elegida

To achieve what you want, you have to add some clearing DIV elements or CSS rules.


data:text/html;charset=utf-8,
<!doctype html public "-//w3c//dtd html 4.01//en">
<head> 
 <title></title>
</head> 
<body>
<blockquote style="background: yellow;" >
 <p style="float: right;" >Lorem</p>
 <hr style="clear: both;" >
 <p style="float: right;" >ipsum</p>
 <div style="clear: both;"></div>
</blockquote>
</body>

Modificadas por cor-el el

more options

What is ‘!doctype’?

I think that:

  • the rule is being shortened by ‘Lorem’ because its margin overlaps it,
  • ‘ipsum’ is lower than ’Lorem’ because of the margin under the rule,
  • ‘ipsum’ is to the left of ‘Lorem’ because the margin under the rule is too narrow.

Correct me if I am wrong. I have probably missed two important points:

  • a float can shorten a rule,
  • margins around a float do not collapse.

Thank you,

Chris

more options

Floats within a container do not make that container adjust its width and height to fit the floats unless you use a clear rule.
So in your case the P elements float, but the HR element doesn't and is rendered first (your code looks the same in Google Chrome as in Firefox).

If you need a more precise explanation about how floats work then it is best to ask advice at the MozillaZine "Web Development/Standards Evangelism" forum.

The helpers at that forum are more knowledgeable about web development issues.
You need to register at the MozillaZine forum site in order to post at that forum.