Funkcjonalność tej witryny będzie ograniczona w czasie konserwacji. Jeśli artykuł nie rozwiązuje twojego problemu i chcesz zadać pytanie, to nasza społeczność wsparcia jest dostępna na @FirefoxSupport na Twitterze i /r/firefox na Reddicie.

Przeszukaj pomoc

Unikaj oszustw związanych z pomocą.Nigdy nie będziemy prosić Cię o dzwonienie na numer telefonu, wysyłanie SMS-ów ani o udostępnianie danych osobowych. Zgłoś podejrzaną aktywność, korzystając z opcji „Zgłoś nadużycie”.

Więcej informacji

Why is a floating box outside its container?

  • 5 odpowiedzi
  • 1 osoba ma ten problem
  • 2 wyświetlenia
  • Ostatnia odpowiedź od 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?

Zmodyfikowany przez cor-el w dniu

Wybrane rozwiązanie

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>
Przeczytaj tę odpowiedź w całym kontekście 👍 0

Wszystkie odpowiedzi (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 >

Zmodyfikowany przez cor-el w dniu

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

Wybrane rozwiązanie

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>

Zmodyfikowany przez cor-el w dniu

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.