CSS Flexbox 之垂直對齊

栏目: CSS · 发布时间: 6年前

内容简介:Flexbox 對於macOS Mojave 10.14.5WebStorm 2019.1.3

Flexbox 對於 垂直對齊 ,並沒有專屬 Property 設定,而是由 row-directionjustify-content 決定。

Version

macOS Mojave 10.14.5

WebStorm 2019.1.3

Safari 12.1.1

CSS 3

HTML

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Flex</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <div class="box">
    <div class="item item1">1</div>
    <div class="item item2">2</div>
    <div class="item item3">3</div>
  </div>
</body>
</html>

對 3 個 <div> 做垂直 layout。

Top Alignment

style.css

.box {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  width: 960px;
  height: 400px;
  margin: auto;
  background-color: #d3d3d3;
}

.item {
  width: 960px;
  height: 120px;
}

.item1 {
  background-color: #faa;
}

.item2 {
  background-color: #afa;
}

.item3 {
  background-color: #aff;
}

第 1行

.box {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

displayflex ,表示使用 flexbox。

flex-directioncolumn ,表示 由上至下

justify-contentflex-start ,因為 由上至下 ,相當於 靠上對齊

CSS Flexbox 之垂直對齊

.box {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
}

flex-directioncolumn-reverse ,表示內容為 由下至上

justify-contentflex-end ,表示從尾部開始對齊,相當於 靠上對齊

CSS Flexbox 之垂直對齊

因為 flex-direction 設定不同,所以前者內容為 由上至下 ,後者為 由下至上 ,但結果都是 靠上對齊

Bottom Alignment

.box {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

flex-directioncolumn ,表示內容為 由上至下

justify-contentflex-end ,表示從尾部開始對齊,相當於 靠下對齊

CSS Flexbox 之垂直對齊

.box {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
}

flex-directioncolumn-reverse ,表示內容為 由下至上

justify-contentflex-start ,表示從頭部開始對齊,相當於 靠下對齊

CSS Flexbox 之垂直對齊

因為 flex-direction 設定不同,所以前者內容為 由上至下 ,後者為 由下至上 ,但結果都是 靠下對齊

Vertical Center Alignment

.box {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

flex-directioncolumn ,表示內容為 由上至下

justify-contentcenter ,相當於 垂直置中

CSS Flexbox 之垂直對齊


以上所述就是小编给大家介绍的《CSS Flexbox 之垂直對齊》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

ASP.NET 2.0技术内幕

ASP.NET 2.0技术内幕

埃斯帕斯托 / 施平安 / 清华大学出版社 / 2006-8 / 68.00元

《ASP.NET2.0技术内幕》围绕着ASP.NET 2.0是Web开发的重要分水岭这一主题,采用自顶向下的方式介绍ASP.NET 2.0的最新编程实践,从更广泛的特征到具体的实现和编程细节,充分展示了ASP.NET的最新编程实践。全书共15章,主题涉及HTTP运行库、安全性、缓存、状态管理、控件、数据绑定和数据访问。   《ASP.NET2.0技术内幕》主题丰富,讲解透彻,包含大量实例,是......一起来看看 《ASP.NET 2.0技术内幕》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具