相关疑难解决方法(0)

在CSS Flexbox中,为什么没有"justify-items"和"justify-self"属性?

考虑flex容器的主轴和横轴:

在此输入图像描述                                                                                                                        资料来源:W3C

要沿主轴对齐flex项,有一个属性:

要沿横轴对齐flex项,有三个属性:

在上图中,主轴是水平的,横轴是垂直的.这些是Flex容器的默认方向.

但是,这些方向可以很容易地与flex-direction财产互换.

/* main axis is horizontal, cross axis is vertical */
flex-direction: row;
flex-direction: row-reverse;

/* main axis is vertical, cross axis is horizontal */    
flex-direction: column;
flex-direction: column-reverse;
Run Code Online (Sandbox Code Playgroud)

(横轴始终垂直于主轴.)

我在描述轴的工作方式时的观点是,任何一个方向似乎都没有什么特别之处.主轴,横轴,它们在重要性方面都是相同的,并且flex-direction可以方便地来回切换.

那么为什么横轴有两个额外的对齐属性呢?

为什么align-content并且align-items合并为主轴的一个属性?

为什么主轴没有justify-self属性?


这些属性有用的场景:

  • 将flex项放在flex容器的角落
    #box3 { align-self: flex-end; justify-self: flex-end; }

  • 制作一组flex项目align-right(justify-content: flex-end)但是让第一个项目对齐left(justify-self: flex-start)

    考虑带有一组导航项和徽标的标题部分.随着justify-self徽标可以左对齐,而导航项目保持最右边,整个事物平滑地调整("弯曲")到不同的屏幕尺寸.

  • 在一排三个柔性物品中,将中间物品粘贴到容器的中心(justify-content: center)并将相邻的物品对齐到容器边缘(justify-self: flex-start …

css w3c language-lawyer flexbox

602
推荐指数
3
解决办法
14万
查看次数

在flexbox中对齐底部

我有容器应根据内容动态改变高度.对于给定行中的所有容器,无论每个容器中的内容如何,​​底部文本都应固定在底部.

.flex-list {
  display: flex;
  flex-direction: column;
}
.flex-list .flex-row {
  display: flex;
  margin-bottom: 20px;
}
.flex-list .flex-row .flex-item-wrapper {
  margin-right: 20px;
  width: 100%;
  background-color: yellow;
}
.flex-list .flex-row .flex-item-wrapper:last-child {
  margin-right: 0px;
  background-color: transparent;
}
.flex-list .flex-row .flex-item-wrapper .flex-item {
  width: 100%;
  height: 100%;
}
.flex-item-stats {
  display: flex;
  justify-content: space-between;
  color: grey;
  padding-top: 10px;
}
.flex-item-stats > * {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.caption {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
Run Code Online (Sandbox Code Playgroud)
<div class="profile-content flex-list"> …
Run Code Online (Sandbox Code Playgroud)

html css css3 flexbox

2
推荐指数
1
解决办法
8204
查看次数

标签 统计

css ×2

flexbox ×2

css3 ×1

html ×1

language-lawyer ×1

w3c ×1