当前位置:网站首页>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
边栏推荐
- Vscade personalization: let a cute girl knock the code with you
- a++,++a,!,~
- [hdu] P6964 I love counting
- JS to determine whether the browser has opened the console
- Openvino CPU acceleration survey
- Psychological analysis of the safest spot Silver
- OOP multiple storage (class template)
- Local deployment and problem solving of IIS in ArcGIS JS 4.23
- Ros2 summer school 2022 transfer-
- E-R图
猜你喜欢

Binary String

Installing MySQL for Linux

A hundred lines of code to realize reliable delay queue based on redis

Debian10 configuring rsyslog+loganalyzer log server

Template specialization template <>

Cadence spb17.4 - Chinese UI settings

Development status of full color LED display

SQL programming task05 job -sql advanced processing

office2016+visio2016

SQL programming task02 job - basic query and sorting
随机推荐
Vector 6 (inheritance)
JMeter associated login 302 type interface
SQL programming task03 job - more complex query
層次選擇器
LeetCode 206. Reverse linked list (iteration + recursion)
Day575: divide candy
Vector 1 (classes and objects)
a++,++a,!,~
SAP ui5 application development tutorial 103 - how to consume third-party libraries in SAP ui5 applications
Graphite statsd interface data format description
SAP mm transaction code vl04 create outbound delivery for sto
C#. Net universal database access encapsulation classes (access, sqlserver, Oracle)
Const defined variables and for of and for in in JS
Philosopher's walk gym divide and conquer + fractal
SAP ui5 application development tutorial 102 - detailed explanation of the print function of SAP ui5 applications
Debian10 configuring rsyslog+loganalyzer log server
How about precious metal spot silver?
[Title Fine brushing] 2023 Hesai FPGA
Use of higher order functions
E-R图