FRONTENDINTERVIEW Telegram 4549
Как работают плавающие элементы (floats)?

float – это CSS-свойство, которое позволяет "выплывать" элементу из обычного потока документа и обтекаться другими элементами (например, текстом).

Пример:
<img src="image.jpg" class="float-img">
<p>Это текст, который будет обтекать картинку.</p>

.float-img {
float: left;
margin-right: 10px;
}


Почему родитель "схлопывается" при использовании float?
Когда внутри div есть только float-элементы, браузер считает, что он пустой, потому что float убирает элемент из потока.
<div class="container">
<img src="image.jpg" class="float-img">
<p>Текст обтекает картинку.</p>
</div>

.container {
background: lightgray;
}
.float-img {
float: left;
}


Решение 1: overflow: hidden;
.container {
overflow: hidden; /* Контейнер теперь учитывает float-элементы */
}


Решение 2: clearfix (старый способ)
.container::after {
content: "";
display: block;
clear: both;
}


Как остановить обтекание (`clear`)?
Чтобы отменить обтекание, используется clear.
<img src="image.jpg" class="float-img">
<p>Этот текст обтекает картинку.</p>
<div class="clear"></div>
<p>Этот текст пойдёт на новую строку.</p>

.float-img {
float: left;
margin-right: 10px;
}
.clear {
clear: both;
}


Почему `float` устарел и что использовать вместо него?
Раньше float использовали для создания колонок и сеток, но сегодня его заменили:
Flexbox (display: flex;) – лучше для адаптивных макетов.
CSS Grid (display: grid;) – мощный инструмент для сложных сеток.
.container {
display: flex;
align-items: center;
}


👉 @frontendInterview



tgoop.com/frontendInterview/4549
Create:
Last Update:

Как работают плавающие элементы (floats)?

float – это CSS-свойство, которое позволяет "выплывать" элементу из обычного потока документа и обтекаться другими элементами (например, текстом).

Пример:

<img src="image.jpg" class="float-img">
<p>Это текст, который будет обтекать картинку.</p>

.float-img {
float: left;
margin-right: 10px;
}


Почему родитель "схлопывается" при использовании float?
Когда внутри div есть только float-элементы, браузер считает, что он пустой, потому что float убирает элемент из потока.
<div class="container">
<img src="image.jpg" class="float-img">
<p>Текст обтекает картинку.</p>
</div>

.container {
background: lightgray;
}
.float-img {
float: left;
}


Решение 1: overflow: hidden;
.container {
overflow: hidden; /* Контейнер теперь учитывает float-элементы */
}


Решение 2: clearfix (старый способ)
.container::after {
content: "";
display: block;
clear: both;
}


Как остановить обтекание (`clear`)?
Чтобы отменить обтекание, используется clear.
<img src="image.jpg" class="float-img">
<p>Этот текст обтекает картинку.</p>
<div class="clear"></div>
<p>Этот текст пойдёт на новую строку.</p>

.float-img {
float: left;
margin-right: 10px;
}
.clear {
clear: both;
}


Почему `float` устарел и что использовать вместо него?
Раньше float использовали для создания колонок и сеток, но сегодня его заменили:
Flexbox (display: flex;) – лучше для адаптивных макетов.
CSS Grid (display: grid;) – мощный инструмент для сложных сеток.
.container {
display: flex;
align-items: center;
}


👉 @frontendInterview

BY Frontend Interview - собеседования по Javascript / Html / Css




Share with your friend now:
tgoop.com/frontendInterview/4549

View MORE
Open in Telegram


Telegram News

Date: |

When choosing the right name for your Telegram channel, use the language of your target audience. The name must sum up the essence of your channel in 1-3 words. If you’re planning to expand your Telegram audience, it makes sense to incorporate keywords into your name. A Hong Kong protester with a petrol bomb. File photo: Dylan Hollingsworth/HKFP. The visual aspect of channels is very critical. In fact, design is the first thing that a potential subscriber pays attention to, even though unconsciously. Deputy District Judge Peter Hui sentenced computer technician Ng Man-ho on Thursday, a month after the 27-year-old, who ran a Telegram group called SUCK Channel, was found guilty of seven charges of conspiring to incite others to commit illegal acts during the 2019 extradition bill protests and subsequent months. With the sharp downturn in the crypto market, yelling has become a coping mechanism for many crypto traders. This screaming therapy became popular after the surge of Goblintown Ethereum NFTs at the end of May or early June. Here, holders made incoherent groaning sounds in late-night Twitter spaces. They also role-played as urine-loving Goblin creatures.
from us


Telegram Frontend Interview - собеседования по Javascript / Html / Css
FROM American