在本文中,我们将带你了解css–具有显示flex的内部容器已损坏在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的CSSdisplay:flex的示例、cssflex之flex-grow|f
在本文中,我们将带你了解css – 具有显示flex的内部容器已损坏在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的CSS display:flex的示例、css flex 之 flex-grow | flex-direction、CSS Flex 容器属性、css flex 容器盒子总结。
本文目录一览:- css – 具有显示flex的内部容器已损坏
- CSS display:flex的示例
- css flex 之 flex-grow | flex-direction
- CSS Flex 容器属性
- css flex 容器盒子总结
css – 具有显示flex的内部容器已损坏
html,body { height: 100%; } body { font-family: sans-serif; } .container { padding: 20px; height: 100%; display: flex; flex-direction: column; flex-grow: 1; }
<div> <h3>Title</h3> <hr/> <div> <p>This is some content</p> </div> </div>
查看this pen.
这种行为在Firefox和Chrome上得到证实.我没有找到任何解释.我该怎么解决?
解决方法
hr
element,预计将以这种风格呈现:
hr { color: gray; border-style: inset; border-width: 1px; margin: 0.5em auto; }
具体来说,请注意margin-left:auto,margin-right:auto.
这些样式用于水平居中的块元素.根据Calculating widths and margins – Block
If both
margin-left
andmargin-right
areauto
,their used values
are equal. This horizontally centers the element with respect to the
edges of the containing block.
在块布局中,如果块具有明确的宽度,则该效果才会显着,否则块将增长以覆盖其所有包含的块.
在FlexBox中,它类似:默认的align-self: auto
和align-items: stretch
使Flex项目增长,以覆盖交叉轴上的Flex线(列布局中的水平线)和auto
margins can also be used to center.
然而,有很大的区别:根据Cross Size Determination,align-self:stretch不会影响具有自动边距的flex项目:
If a flex item has 07006,its computed cross size
property isauto
,and neither of its cross-axis margins areauto
,
the used outer cross size is the used cross size of its flex line,
clamped according to the item’s min and max cross size properties.
Otherwise,the used cross size is the item’s 07007.
然后,您可以通过删除自动边距来解决此问题:
hr { margin-left: 0; margin-right: 0; }
.container { padding: 20px; display: flex; flex-direction: column; } hr { margin-left: 0; margin-right: 0; }
<div> <h3>Title</h3> <hr /> <div> <p>This is some content</p> </div> </div>
或者,通过宽度或最小宽度强制一定宽度将抵消由自动边缘引起的收缩(更技术上,缺乏拉伸).
CSS display:flex的示例
0.前言
在编写下图类似的HTML时,我最初使用的float,发现浮动的写法很不方便,后面经百度改用display:flex进行布局,并对这一CSS属性产生了浓厚的兴趣。
通过几行代码轻松解决了左右对齐显示,并且意外发现通过 align-items: center 还可以实现上下对齐居中
我正在使用 styled-components 去实现前端效果,所以代码分为样式部分style.js和页面部分index.js
style.js:
1 export const Legend = styled.div`
2 width: 100%;
3 display: flex;
4 display: -webkit-flex;
5 margin:10px 0px;
6
7 .left {
8 text-align: left;
9 font-size: 16px;
10
11 img{
12 margin-right: 5px;
13 }
14 }
15
16 .right {
17 flex: 1;
18 display: flex;
19 display: -webkit-flex;
20 align-items: center;
21 justify-content: flex-end;
22 }
23 `;
index.js:
1 <Divider>图例</Divider>
2 {
3 this.state.thematicLayers.length>0?(
4 this.state.thematicLayers.map(item => {
5 return (
6 <Legend>
7 <div className=''left''>
8 <img src={item.tPic} />{item.tName}
9 </div>
10 <div className=''right''>
11 <Switch />
12 </div>
13 </Legend>
14 )
15 })
16 ):(
17 <div>暂无图层数据</div>
18 )
19 }
下面进入正题,Flex是弹性布局的意思,可以为任意元素指定为Flex布局
1 .box{
2 display: flex;
3 display: -webkit-flex; /*兼容Safari(ios)*/
4 }
1.flex-direction 属性
主要参数: row | row-reverse | column | column-reverse
主要代码:
1 export const FlexBox = styled.div`
2 width: 1000px;
3 margin: 0 auto;
4 background: #7B68EE
5 display: flex;
6 display: -webkit-flex;
7 flex-direction: row | row-reverse | column | column-reverse;
8 `;
9
10 export const FlexBoxItem = styled.div`
11 background: #FFD700;
12 width: ${props => props.width?props.width:''100px''};
13 height: ${props => props.width?props.width:''100px''};
14 margin: 10px;
15 `;
row
(默认)水平方向,起点在左端
row-reverse
水平方向,起点在右端
column
垂直方向,起点在上边沿

2.flex-warp 属性
主要参数:nowrap | wrap | wrap-reverse
主要代码:
1 export const FlexBox = styled.div`
2 width: 500px;
3 margin: 0 auto;
4 margin-top: 100px;
5 background: #7B68EE
6 display: flex;
7 display: -webkit-flex;
8 flex-warp: nowrap | wrap | wrap-reverse;
9 `;
10
11 export const FlexBoxItem = styled.div`
12 background: #FFD700;
13 width: ${props => props.width?props.width:''100px''};
14 height: ${props => props.width?props.width:''100px''};
15 margin: 10px;
16 `;
nowrap
不换行,会挤在一行,之前设定的宽度会失效,margin仍有效,图一为三个,图二为多个


wrap
换行,且第一行在上方
换行,且第一行在下方

3.flex-flow属性


4.justify-content属性
主要参数: flex-start | flex-end | center | left | right | space-between | space-around | space-evenly | stretch | safe | unsafe | baseline | first baseline | last baseline

flex-end
终点对齐,注意这边和上面的flex-direction:row-reverse不同,他并没有调整子元素的顺序
center
居中
space-around


5.align-items 属性
主要参数: flex-start | flex-end | center | baseline | stretch

flex-end
靠下对齐
center
垂直居中(贼好用,我不管我要标红)
baseline
第一行文字对齐,这个可以用来做效果
大致就是以上这些,连代码带查资料写了2个多小时,脑壳疼
css flex 之 flex-grow | flex-direction
总结
以上是小编为你收集整理的css flex 之 flex-grow | flex-direction全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
CSS Flex 容器属性
以下是 CSS Flex 容器属性
- flex-direction
- flex-wrap
- flex-flow
- 对齐内容
- 对齐项目
- 对齐内容
以上就是CSS Flex 容器属性的详细内容,更多请关注php中文网其它相关文章!
css flex 容器盒子总结
css flex 容器盒子总结(很有用,工作中经常用到)
- display: flex (块布局)| inline-flex(行内布局);
- flex-direction: row(默认值) | row-reverse | column | column-reverse;决定主轴的方 向(即项目的排列方向)
- flex-wrap: nowrap(默认值) | wrap | wrap-reverse; 决定容器内项目是否可换行
- flex-flow: 这个属性基本没啥用
- justify-content: flex-start(左对齐-默认值) | flex-end(右对齐) | center(居中) | space-between(两端对齐)|space-around(每个项目两侧的间隔相等); 定义了项目在主轴的对齐方式。
- align-items:flex-start(交叉轴起点对齐)| flex-end(交叉轴终点对齐) | center (交叉轴中点对齐)| baseline(项目的第一行文字的基线对齐) | stretch(若子项目无设置高度,则100%占满容器高度, (默认值)); 定义了项目在交叉轴上的对齐方式
- align-content:flex-start | flex-end | center | space-between | space-around | stretch(默认值); 多根轴线的对齐方式,如果项目只有一根轴线,那么该属性将不起作用(即当flex-wap 设置为wap 可换行的情况下, align-content才有效,即在交叉轴上的对齐方式)
先总结这么多, 有时间了增加图例解释
我们今天的关于css – 具有显示flex的内部容器已损坏的分享就到这里,谢谢您的阅读,如果想了解更多关于CSS display:flex的示例、css flex 之 flex-grow | flex-direction、CSS Flex 容器属性、css flex 容器盒子总结的相关信息,可以在本站进行搜索。
本文标签: