


The difference between display:inline-block and float in css when arranging elements in a row
During layout, many designs need to arrange elements in a row. There are many ways to arrange elements in a row. From the perspective of compatibility and ease of use, we will first introduce display:inline-block (display within block) and float (float).
float: Float, you will know its meaning after hearing its name: making elements float and break away from the document flow, so as to achieve the purpose of arranging multiple elements in a row. What are the characteristics of floating elements? As shown below:
supports width and height;
## is displayed in one line;
- When the width is not set, the width is supported by the content;
- will move in the specified order until it encounters the float The boundary of the element or parent stops;
- After the element is floated, the height of the parent of the floating element will collapse;
- It breaks away from the document flow;
- After the element floats, the upper and lower margins no longer overlap;
- triggers BFC.
- supports width and height;
- is displayed in one line;
- code wraps Will be parsed into spaces;
- When the width is not set, the width will be stretched by the content;
- Inline-block type elements will have a by default at the bottom Gap;
- The upper and lower margins of inline-b type elements do not overlap;
- triggers BFC.
- Arrangement direction limitation. The fourth characteristic of float determines that it can determine the order of elements. float:left: elements are arranged from left to right, float:right: elements are arranged from right to left. And display:inline-block can only be used from left to right.
- Whether to break away from the document flow. Floated elements will break out of the document flow, but display:inline-block will not. So there will be a phenomenon: when the first floating element or inline-block element already occupies a row, and add margin-left:-100% to the second element, the second floating element will cover the second floating element. On top of the element, the second inline-block will be displayed in a new line and moved according to the margin-left;
- The floating element will collapse to the height of the parent. In order to avoid the height collapse of the parent element, this feature must be processed when using float: set the height of the parent or clear the float;
- inline-block There is a gap at the bottom of the element by default. When making web pages, you need to set the vertical alignment: vertical-align to eliminate gaps;
- Inline-block type elements will generate spaces when the HTML code wraps. In order to eliminate the impact of spaces , need: write the inline element as one line in the structure or set the font-size of the parent of the inline element to 0 in the style;
The above is the detailed content of The difference between display:inline-block and float in css when arranging elements in a row. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Fujifilm fans were recently very excited at the prospect of the X-T50, since it presented a relaunch of the budget-oriented Fujifilm X-T30 II that had become quite popular in the sub-$1,000 APS-C category. Unfortunately, as the Fujifilm X-T50's launc

Maximum value of float: 1. In C language, the maximum value of float is 3.40282347e+38. According to the IEEE 754 standard, the maximum exponent of the float type is 127, and the number of digits of the mantissa is 23. In this way, the maximum floating point number is 3.40282347 e+38; 2. In the Java language, the maximum float value is 3.4028235E+38; 3. In the Python language, the maximum float value is 1.7976931348623157e+308.

Apple Studio Display is now officially available in stores, and many customers around the world have purchased the product. Unlike the ProDisplayXDR, the StudioDisplay has a unique power connector that appears to be non-removable. It turns out that the cable is removable, but you'll need a special tool to remove it. Apple says on its website that the Studio Display's power cord is not detachable -- and many users think so. That's because removing the cable with your hands seems impossible, but luckily the cable can be detached from the monitor. , Apple has a special tool for extracting information from its new StudioDispl

Samsung Smart Display M8 vs. Apple Studio Display: Design and Size Since its launch, the Apple Studio Display has been compared to the iMac, consisting of a relatively thin panel on a relatively simple L-shaped stand. It's a well-known and well-loved aesthetic, and Samsung seems to have borrowed it for its presentation. The Samsung SmartMonitor M8 uses the same idea of a thin screen on a stand that looks very similar. Some minor elements are different, such as the small section in the lower left corner that sticks out a bit and the Samsung's chin is very thin, but they seem to be close in terms of basic design. Samsung seems to have taken a lot of inspiration from the 24-inch iMac. Apple's display is smaller than Samsung's

We frequently report on devices based on displays with electronic ink, such as e-readers. The technology offers a number of advantages: it can be read in bright environments without a backlight, and it only requires power when switching without light

StudioDisplay and LG UltraFine5KDisplay occupy similar positions in the market, but Apple's monitor is $300 more expensive. Here's everything you need to know about how these monitors compare. Six years is a long time in the tech world, and it's also the time since Apple has sold a branded monitor that costs less than $5,000. During this time, Apple partnered with LG to sell the LG UltraFine series, which catered specifically to Mac users. In 2019, Apple stopped selling these LG monitors in favor of ProDisplayXDR, an affordable Mac-friendly display

IntelMac users running Windows on a Mac can now update their drivers in BootCamp to support Apple's StudioDisplay. Apple regularly updates BootCamp to introduce support for new hardware, as well as typical compatibility and performance improvements. In the March software update, Apple has enabled BootCamp to work with the new StudioDisplay. The update that brings BootCamp to version 6.1.17 introduces two key support elements. First, it adds compatibility with StudioDisplay, ensuring

The values of display include block, inline, none, inline-block, flex, grid, table, inline-table and list-item. Detailed introduction: 1. block, which renders elements into block-level elements. Block-level elements form a block on the page and occupy one line alone; 2. inline, which renders elements into inline elements. Inline elements will not occupy a line by themselves and can be side by side with other elements; 3. none, this value specifies that the element will not be on the page, etc.
