- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下 HTML
<div class="container">
<div class="box box1">one 😎</div>
<div class="box box2">two 🍕</div>
<div class="box box3">three 🍟</div>
<div class="box box4">four 👍</div>
<div class="box box5">five 👀</div>
<div class="box box6">six 💩</div>
</div>
并使用 flexbox 使用此 CSS 设置样式
.container {
display:flex;
flex-wrap:wrap;
}
.box {
flex-basis:500px;
flex-grow:1;
}
.box3 {
flex-grow:10;
}
我假设 flex-grow:10;
会使 box 3
10 倍 比 box 4
出现在我的屏幕上,但我看到了这个:
为什么这不是大 10 倍?
这里是相对的CodePen
最佳答案
Is flex-grow affected by flex-basis?
在某种程度上,是的,因为 flex-grow
所做的是分配剩余的空间,在元素的大小减小之后,元素的大小可以通过内容或显式设置来调整。
例如,如果父项的宽度为 1000 像素,有 2 个子项,每个子项的宽度为 300 像素,则剩余空间将为 1000px-300px-300px = 400px。
如果一个child的flex grow值为1,另一个child为10,则前者为300px+(1/11*400px),后者为300px+(10/11*400px)
在这里阅读更多关于 flex-grow
的信息
因此,在您的情况下,每个元素设置为 500px,每行 2 个,当 剩余空间 时,该空间将在除 box3
以外的所有行上平均共享。在该行上,空间将与 10/11 共享 box3
,1/11 共享另一行。
在每行 3 个元素的情况下,box3
的共享将为 10/12,另外两个各为 1/12。
Why is this not 10 times bigger?
在这种情况下,当在元素上设置宽度时,flex-grow
在元素之间分配剩余的可用空间。
如果您想使用 flex-grow
来调整元素的大小,请给它们一个 flex-basis
的 0
。这将使 flex-grow
的计算相信这些元素是空的,并且它会大 10 倍。
/* We start writing out flexbox here. The above is just page setup */
.container {
display:flex;
flex-wrap:wrap;
}
.box {
flex-basis:0;
flex-grow:1;
overflow: hidden; /* to allow items to be smaller
than its content */
}
.box3 {
flex-grow:10;
}
/* CSS Normalize */
article,aside,details,figcaption,figure,footer,header,hgroup,nav,section,summary{display:block;}audio,canvas,video{display:inline-block;}audio:not([controls]){display:none;height:0;}[hidden]{display:none;}html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;}a:focus{outline:thin dotted;}a:active,a:hover{outline:0;}h1{font-size:2em;}abbr[title]{border-bottom:1px dotted;}b,strong{font-weight:700;}dfn{font-style:italic;}mark{background:#ff0;color:#000;}code,kbd,pre,samp{font-family:monospace, serif;font-size:1em;}pre{white-space:pre-wrap;word-wrap:break-word;}q{quotes:\201C \201D \2018 \2019;}small{font-size:80%;}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}sup{top:-.5em;}sub{bottom:-.25em;}img{border:0;}svg:not(:root){overflow:hidden;}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em;}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0;}button,input{line-height:normal;}button,html input[type=button],/* 1 */
input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer;}button[disabled],input[disabled]{cursor:default;}input[type=checkbox],input[type=radio]{box-sizing:border-box;padding:0;}input[type=search]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box;}input[type=search]::-webkit-search-cancel-button,input[type=search]::-webkit-search-decoration{-webkit-appearance:none;}textarea{overflow:auto;vertical-align:top;}table{border-collapse:collapse;border-spacing:0;}body,figure{margin:0;}legend,button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}
/* Box-sizing border-box */
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }
/* Some default styles to make each box visible */
.box {
color:white;
font-size: 50px;
text-align: center;
text-shadow:4px 4px 0 rgba(0,0,0,0.1);
padding:10px;
}
/* Colours for each box */
.box1 { background:#1abc9c;}
.box2 { background:#3498db;}
.box3 { background:#9b59b6;}
.box4 { background:#34495e;}
.box5 { background:#f1c40f;}
.box6 { background:#e67e22;}
.box7 { background:#e74c3c;}
.box8 { background:#bdc3c7;}
.box9 { background:#2ecc71;}
.box10 { background:#16a085;}
<div class="container">
<div class="box box1">one 😎</div>
<div class="box box2">two 🍕</div>
<div class="box box3">three 🍟</div>
<div class="box box4">four 👍</div>
<div class="box box5">five 👀</div>
<div class="box box6">six 💩</div>
</div>
关于html - flexbox 的增长是否受 flexbox-basis 的影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48380575/
我面临着让一个相当复杂的网络应用程序在 HTML/CSS 中工作的问题。我发现 flexbox 有很多问题,这似乎可以解决我的问题。我试图了解我做错了什么或 flexbox 的限制是什么。我只在 Ch
尝试扩展 FlexBox 容器内输入的宽度。我希望它与父容器具有相同的宽度。这是我的 view.xml:
尝试扩展 FlexBox 容器内输入的宽度。我希望它与父容器具有相同的宽度。这是我的 view.xml:
我有两个 flexbox,它们在高度变化时收缩,嵌套内容重叠。 如何防止这种情况? 最佳答案 just add flex-shrink:0 to your element and the flexbo
我对 FlexBoxes 有疑问 - 我想要 我想将页面的一个部分分成两部分(相同高度),例如每个 100 像素 这些部分之一(第 2 个)我想分成三个小部分(等高)100/3 = 33px 下面的代
我的内容布局由三个部分组成:页眉、内容和页脚。对于小型设备,我想保留此顺序,在桌面设备上,我想将页眉和页脚移至侧边栏。 使用 float 实现:http://codepen.io/anon/pen/j
我正在尝试实现以下布局: +---------+---------------------+ |legend | | +---------+
我在尝试使用 Flexbox 进行某些标记时遇到问题。我制作了这个代码笔来演示我的问题:http://codepen.io/anon/pen/QjbzJY?editors=110 我希望左侧的图像(.
我正在尝试获得一个看起来有点像这样的用户界面: 在图片中,假装带有“New York...”的顶部栏和“Book it”按钮是固定的,并且它们之间的内容是可滚动的。 到目前为止,我的 HTML 是这样
我尝试调整一些动态内容,使其适合要打印的标签。 标签有一行 (.symbolContainer),可以包含 0 个或多个图像。目标是在 .text 框的内容需要更多空间时缩小 .symbolConta
我是 Stack Overflow 的新手,我遇到了 flexbox 的问题。 我想使用 和 与 display: flex;其中 main 的每一行都有 2 列 height: 100%浏览器和页脚
我想创建一个带有部分的水平 slider 。 Section 1 Card 1 ... Section 2 Card 1 ... ...
在给定的代码中,我需要识别第一行的最后一个元素和最后一行的第一个元素。只是为了让它从各个 Angular 落变圆。我怎样才能做到这一点?我需要在这里提到的是,根据屏幕尺寸,列号以及第一行的最后一个元素
我花了一整天的时间来完成这项工作。虽然我可以使用一个 flex 盒,但当一个 flex 盒要包含另一个 flex 盒时就会变得很麻烦。 我试着按照这个问题的提示去做: Flexbox inside a
在我的测试中(以及我的其他 SO 问题的回答),当 flexbox 占用页面的整个宽度或具有固定宽度的父元素时,它可以很好地处理溢出文本。但是,如果具有动态宽度的 flexbox 在另一个动态宽度 f
我正在尝试让一个 flexbox 在 flexbox 内部工作。当第一个(包装)flexbox 工作时,里面的那个什么都不做。无论如何让这个工作? 我想要做的是有效地拥有两个粘性页脚,并且两者的高度都
我正在尝试使用 flexboxes 并想组合一个列和行容器。我的问题是: 为什么放置在列中的行元素没有跨越 flex 容器的整个宽度? 此处显示示例代码:js-fiddle HTML: /* CSS:
目标 我正在使用 SASS 开发一个基于 flexbox + calc() 的 grid system with gutters。 您可以像这样通过混合定义网格: .box { @inc
在IE11下运行时,下面的例子会在itemwrapper的底部添加空格元素。在开发控制台中检查时,此空间不归因于边距、填充或边框。测量子元素的高度似乎是一个问题,因为如果给它们一个固定的高度,那么空间
我的目标是在 Angular 5 项目中使用 ag-grid,并让网格占据 Flexbox 布局中的所有可用垂直空间。当网格包含在具有定义的像素高度的 div 中时,或者当 div 具有百分比高度但不
我是一名优秀的程序员,十分优秀!