P
P
Pavel2019-10-26 15:53:39
css
Pavel, 2019-10-26 15:53:39

Why doesn't float create a line break?

I read: "Block elements are characterized by the fact that they take up the entire available width, the height of the element is determined by its content, and it always starts on a new line."
I understand on the fingers:

<div class="" style="background-color: red;">Первый </div>
  <div class="" style="background-color: green;>Второй </div>
  <div class="" style="background-color: yellow;">Третий </div>

While everything is logical. Each block starts on a new line.
But adding a float
<div class="" style="background-color: red;">Первый </div>
  <div class="" style="background-color: green; float: right">Второй </div>
  <div class="" style="background-color: yellow;">Третий </div>

5db4400831b46905443255.png
the second and third blocks are on the same line.
Why is the third div not displayed from the third line, but "jumps" to the second one? Why does float suddenly break the definition of block-level elements when it is explicitly stated that "it always starts on a new line"?
Probably the most logical answer is: "because it's a float" - but I can't figure out "how it works", even though I googled both the div and the float specification.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pautov, 2019-10-26
@bootd

Why does float suddenly break the definition of block elements
so because it wraps the element. First, read about its properties. An element given a float will wrap around the previous element

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question