当前位置:网站首页>Foundation Consolidation - Flex width is content width
Foundation Consolidation - Flex width is content width
2022-06-23 01:31:00 【hhzzcc_】
Official account , You can get a red envelope for takeout every day

When setting labels display: flex The default label has display: block Characteristics of , The width will fill up according to the parent element , as follows
<div class="box-parent"><div class="box">box</div></div>
.box-parent {width: 300px;}.box {display: flex;background: #fff;}
In the above code box Set up flex Layout , The default width is the same as the parent element 300px, Here's the picture

But most of the time, all we need is to follow the content , Here's the picture

There are three solutions :
Method 1 : The parent element is also set to flex
.box-parent {display: flex;width: 300px;}
because flex Layout sub elements (.box)flex-grow Property defaults to 0( If .box Set up flex-grow: 1 Then it will be full of parent elements ), That is, do not deal with the remaining space , Achieve the effect of maintaining the current content size
Method 2 : Set up box width by fit-content
.box {width: fit-content;}
take width Set to fit-content Make an element have ' Inclusion ', The width is also determined by the content , About fit-content also min-content、max-content、fill-available, You can read this article by Xuda
https://www.zhangxinxu.com/wordpress/2016/05/css3-width-max-contnet-min-content-fit-content/
Method 3 :inline-flex
.box {display: inline-flex;}
inline-flex and inline-block similar , keep flex At the same time, it is the characteristics of inline elements
边栏推荐
- [ZOJ] P3228 Searching the String
- Swiftui swift tutorial 14 useful array operators
- Get the start and end dates of the current week
- Use elk to save syslog, NetFlow logs and audit network interface traffic
- It's still like this
- Add / get and delete cookies
- [UVM] don't say that your VIP can't use ral model
- Pat class A - 1012 the best rank (PIT)
- Pat class A - 1015 reversible primes
- Wallys/DR7915-wifi6-MT7915-MT7975-2T2R-support-OpenWRT-802.11AX-supporting-MiniPCIe
猜你喜欢

New progress in the construction of meituan's Flink based real-time data warehouse platform
![[launch] redis Series 2: data persistence to improve availability](/img/f4/5bc7ca3e17c6656e71df515182842e.png)
[launch] redis Series 2: data persistence to improve availability

Sfod: passive domain adaptation and upgrade optimization, making the detection model easier to adapt to new data

Lexical Sign Sequence

Charles garbled code problem solving

Explain the startup process of opengauss multithreading architecture in detail

On AI and its future trend | community essay solicitation

E-R图

OSPF comprehensive experiment

E-R diagram
随机推荐
关于打算做一个web的问题看板,需要使用哪些方面语言及数据库知识!
Install MySQL (5.7+8.0) through docker and configure master-slave replication (gtid+ enhanced semi synchronization)
[cmake command notes]find_ path
Pat class A - 1012 the best rank (PIT)
Day500: keyboard line
Installing MySQL for Linux
[learning notes] roll back Mo team
[hdu] P6964 I love counting
Population standard deviation and sample standard deviation
Autumn move script a
Node fetch download file
Pat class a 1016 phone bills (time difference)
Cadence spb17.4 - Chinese UI settings
層次選擇器
Local deployment and problem solving of IIS in ArcGIS JS 4.23
Yyds dry inventory solution sword finger offer: print the binary tree into multiple lines
[ZOJ] P3228 Searching the String
Pat class A - 1007 maximum subsequence sum
Webdriver and selenium Usage Summary
MySQL-Seconds_ behind_ Master accuracy error