Get the App
SLTechnology News&Howtos  ›  Development  › 

How does CSS make the surrounding elements make room for floating elements

Shulou Source: shulou.com Published: 2022-06-01 05:24:50 10月04日 Update

This article mainly explains "CSS how to make room for floating elements around". The explanation in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "CSS how to make room for floating elements".

To achieve this effect, add enough space to the top and outer margins of the cleaned element so that the top edge of the element falls vertically below the floater:

This is an effective thing that allows nearby elements to make room for floating elements.

Let's look at floats and cleanups in more detail. If you want an image to float to the right of the text block, not to mention that the picture and text are collected in another element with a post-aid color collection and border. You can write the following code:

.news {background-color: gray; border: solid 1px black;}. News img {float: left;}. News p {float: right;}

Some text

Under such circumstances, a problem arises. Because floating elements come to the document stream, the div that surrounds images and text does not conquer space.

Thank you for your reading, the above is the content of "how CSS allows the surrounding elements to set aside space for floating elements". After the study of this article, I believe you have a deeper understanding of how CSS allows the surrounding elements to make room for floating elements. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Elements floats spaces pictures text learning content questions validity stuff code utility right backup that is ideas situations documents articles more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi MariaDB Shulou Tech Info Xiaomi