使用flex实现5种常用结构(flex常用的属性)

作者:锄禾啊飞
围观群众:4
更新于
使用flex实现5种常用结构(flex常用的属性)

当页面内容高度小于可视区域高度时,footer 吸附在底部;当页面内容高度大于可视区域高度时,footer 被撑开排在 content 下方

demo link


<body>
  <header>HEADER</header>
  <article>CONTENT</article>
  <footer>FOOTER</footer>
</body>
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
article {
  flex: auto;
}


Fixed-Width Sidebar

在上-中-下结构的基础上,加了左侧定宽 sidebar。

demo link


<body>
  <header>HEADER</header>
  <div class="content">
    <aside>ASIDE</aside>
    <article>CONTENT</article>
  </div>
  <footer>FOOTER</footer>
</body>
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.content {
  flex: auto;
  display: flex;
}
.content article {
  flex: auto;
}


Sidebar

左边是定宽 sidebar,右边是上-中-下结构。

demo link


<body>
  <aside>ASIDE</aside>
  <div class="content">
    <header>HEADER</header>
    <article>CONTENT</article>
    <footer>FOOTER</footer>
  </div>
</body>
body {
  min-height: 100vh;
  display: flex;
}
aside {
  flex: none;
}
.content {
  flex: auto;
  display: flex;
  flex-direction: column;
}
.content article {
  flex: auto;
}


Sticky Header

照样上-中-下结构,区别是 header 固定在顶部,不会随着页面转动。

使用flex实现5种常用结构(flex常用的属性)

demo link


<body>
  <header>HEADER</header>
  <article>CONTENT</article>
  <footer>FOOTER</footer>
</body>
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: 60px;
}
header {
  height: 60px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 0;
}
article {
  flex: auto;
  height: 1000px;
}


Sticky Sidebar

左侧 sidebar 固定在左侧且与视窗同高,当内容超出视窗高度时,在 sidebar 内部泛起转动条。左右两侧转动条相互自力。

demo link

使用flex实现5种常用结构(flex常用的属性)


<body>
  <aside>
    ASIDE
    <p>item</p>
    <p>item</p>
    <!-- many items -->
    <p>item</p>
  </aside>
  <div class="content">
    <header>HEADER</header>
    <article>CONTENT</article>
    <footer>FOOTER</footer>
  </div>
</body>
body {
  height: 100vh;
  display: flex;
}
aside {
  flex: none;
  width: 200px;
  overflow-y: auto;
  display: block;
}
.content {
  flex: auto;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.content article {
  flex: auto;
}


泉源:https://github.com/meikidd/flex-layout


使用flex实现5种常用结构(flex常用的属性)
思源资源网:分类流动

1.阿里云: 本站现在使用的是阿里云主机,平安/可靠/稳固。点击领取2000米代金券、领会最新阿里云产物的种种优惠流动点击进入

使用flex实现5种常用结构(flex常用的属性)

2.腾讯云: 提供云服务器、云数据库、云存储、视频与CDN、域名等服务。腾讯云各种产物的最新流动,优惠券领取点击进入

使用flex实现5种常用结构(flex常用的属性)

3.广告同盟: 整理了现在主流的广告同盟平台,若是你有流量,可以作为参考选择适合你的平台点击进入

链接: http://www.fly63.com/article/detial/218

非特殊说明,本文版权归 原百分享网 所有,转载请注明出处.

本文分类: 生活

本文标题: 使用flex实现5种常用结构(flex常用的属性)

本文网址: http://www.sshyvip.com/shenghuo/5804.html

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

网站分类
搜索
最新留言
    标签列表