Use flexbox to create a responsive website, containing a flexible navigation bar and flexible content:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
} /* Style the body */
body {
font-family: Arial;
margin: 0;
} /* Header/logo Title */
.header {
padding: 60px;
text-align: center;
background: #1abc9c;
color: white;
} /* Style the top navigation bar */
.navbar {
display: flex;
background-color: #333;
} /* Style the navigation bar links */
.navbar a {
color: white;
padding: 14px 20px;
text-decoration: none;
text-align: center;
} /* Change color on hover */
.navbar a:hover {
background-color: #ddd;
color: black;
} /* Column container */
.row {
display: flex;
flex-wrap: wrap;
} /* Create two unequal columns that sits next to each other */
/* Sidebar/left column */
.side {
flex: 30%;
background-color: #f1f1f1;
padding: 20px;
} /* Main column */
.main {
flex: 70%;
background-color: white;
padding: 20px;
} /* Fake image, just for this example */
.fakeimg {
background-color: #aaa;
width: 100%;
padding: 20px;
} /* Footer */
.footer {
padding: 20px;
text-align: center;
background: #ddd;
} /* Responsive layout - when the screen is less than 700px wide, make the two columns stack on top of each other instead of next to each other */
@media screen and (max-width: 700px) {
.row, .navbar {
flex-direction: column;
}
}
</style>
</head>
<body> <!-- Note -->
<div style="background:yellow;padding:5px">
<h4 style="text-align:center">Resize the browser window to see the responsive effect.</h4>
</div> <!-- Header -->
<div class="header">
<h1>My Website</h1>
<p>With a <b>flexible</b> layout.</p>
</div> <!-- Navigation Bar -->
<div class="navbar">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div> <!-- The flexible grid (content) -->
<div class="row">
<div class="side">
<h2>About Me</h2>
<h5>Photo of me:</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text about me in culpa qui officia deserunt mollit anim..</p>
<h3>More Text</h3>
<p>Lorem ipsum dolor sit ame.</p>
<div class="fakeimg" style="height:60px;">Image</div><br>
<div class="fakeimg" style="height:60px;">Image</div><br>
<div class="fakeimg" style="height:60px;">Image</div>
</div>
<div class="main">
<h2>TITLE HEADING</h2>
<h5>Title description, Dec 7, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
<br>
<h2>TITLE HEADING</h2>
<h5>Title description, Sep 2, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
</div>
</div> <!-- Footer -->
<div class="footer">
<h2>Footer</h2>
</div> </body>
</html>

Flexbox Elements

To start using the Flexbox model, you need to first define a flex container.

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
background-color: DodgerBlue;
} .flex-container > div {
background-color: #f1f1f1;
margin: 10px;
padding: 20px;
font-size: 30px;
}
</style>
</head>
<body> <div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div> <p>A Flexible Layout must have a parent element with the <em>display</em> property set to <em>flex</em>.</p> <p>Direct child elements(s) of the flexible container automatically becomes flexible items.</p> </body>
</html>

The flex container properties are:

The flex-direction Property

The flex-direction property defines in which direction the container wants to stack the flex items.

 column: (from top to bottom)
 row: (from bottom to top)
The column-reverse value stacks the flex items vertically (but from bottom to top)

The row-reverse value stacks the flex items horizontally (but from right to left)

The flex-wrap Property

The flex-wrap property specifies whether the flex items should wrap or not.

CSS: Flexbox的更多相关文章

  1. CSS Flexbox 学习指南、工具与框架

    Flexbox 是一种更有效的布局方式,它能更好的分配容器空间,并控制项目的对齐.虽然,掌握它的理论有些复杂,但幸运的是,我们可以借助开放的网络来学习并逐步掌握它. 在本文中,我们整合了一些最佳的 F ...

  2. CSS Flexbox 弹性盒子模型

    CSS Flexbox 弹性盒子模型 设置元素样式为 display: flex 或 display: inline-flex, 让元素变成flex容器, 从而可以通过flex模式布局它的子元素. f ...

  3. CSS#Flex-box, border-size, onresize() event, Media Queries

    Flexbox Pseudo-classes box-sizing: border-box HTML DOM event  resize() @media Queries: 根据一些css条件,触发一 ...

  4. css flexbox 弹性布局

    flexbox 即css flexible box layout. ie9及以下不支持flexbox. flex详细规范(https://www.w3.org/TR/css-flexbox/) 为什么 ...

  5. 使用css Flexbox实现垂直居中

    CSS布局对我们来说一直是个噩梦,我们都认为flexbox是我们的救世主.是否真的如我们说说,还有待观察,但是flexbox确非常轻松的解决css长久一来比较难解决的居中问题.让我们来看看到底有多容易 ...

  6. css flexbox水平垂直

    display: -webkit-box;display: -webkit-flex;display: -moz-box;display: -moz-flex;display: -ms-flexbox ...

  7. css FlexBox 弹性盒子常用方法总结

    总结一下弹性盒子常用的方法,弹性盒子的功能强大,这次我做了兼容性的felxbox,虽然代码多了一点,但在项目时候可以直接复制过来用,同时在项目上线的时候,如果这时候弹性盒子出了兼容问题,那就可急了~ ...

  8. Flex布局(CSS Flexbox)

    参考:Flex 布局语法教程 Flex布局是什么? Flex是Flexible Box的缩写,意为”弹性布局”,用来为盒状模型提供最大的灵活性. 任何一个容器都可以指定为Flex布局 注意:设为Fle ...

  9. 分享15个优秀的 CSS 解决方案和工具

    CSS 代码是很难管理,尤其是在大型项目. 样式都写在一个全局作用域里,通过复杂的选择器来指向特定的页面元素.冗余.膨胀和维护可以成为前端开发人员的一场噩梦.幸运的是我们有一些 CSS 工具来帮助开发 ...

随机推荐

  1. SQL2000查看表的大小

    SQL2000查看表的大小 标签: sqlsql server数据库报表tableinsert 2011-06-08 11:47 4013人阅读 评论(0) 收藏 举报 SQL2000查看表的大小 本 ...

  2. 17届计算机应届生秋季校招分享 to Tomorrow

    首先自我介绍一下,本人来自普通二本院校,计算机科学与技术专业,在校有一到两年asp.net项目经验,花了两个星期左右的时间转向java.现将此次的求职经历,分为三阶段,分享给大家. First Sta ...

  3. 基本运算符与流程控制(Day5)

    一  运算符 1.算数运算 2.比较运算 3.赋值运算 4.逻辑运算 and注解: 在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样,但是它们并不返回布尔值:而是,返回它们实际 ...

  4. day2 笔记

    while 条件:           # 循环体       # 如果条件为真,那么循环体则执行     # 如果条件为假,那么循环体不执行         循环中止语句 如果在循环的过程中,因为某 ...

  5. python数据可视化、数据挖掘、机器学习、深度学习 常用库、IDE等

    一.可视化方法 条形图 饼图 箱线图(箱型图) 气泡图 直方图 核密度估计(KDE)图 线面图 网络图 散点图 树状图 小提琴图 方形图 三维图 二.交互式工具 Ipython.Ipython not ...

  6. 在 ReportViewer 报表中使用表达式

    from:http://www.cnblogs.com/jobin/articles/1152213.html 有些表达式在报表中很常用.其中包括更改报表中的数据外观的表达式.计算总数的表达式和更改报 ...

  7. jmeter常用插件安装

    转载:http://www.cnblogs.com/danqiu/p/6119156.html 下载地址:http://jmeter-plugins.org/downloads/all/ PerfMo ...

  8. LVS管理工具--ipvsadm

    一. ipvsadm工具介绍 从2.4版本开始,linux内核默认支持LVS.要使用LVS的能力,只需安装一个LVS的管理工具:ipvsadm. LVS的结构主要分为两部分: 工作在内核空间的IPVS ...

  9. 登录用户执行sudo时报错

    场景: 以普通用户登录,登陆后切换至root或其他用户时报错(sudo su -或sudo -i) 报错信息: -bash: /bin/logger: Argument list too long 根 ...

  10. 禁止电脑登陆QQ聊天系统的四种方法

    一.使用防火墙禁止端口法 QQ使用的默认端口是 UDP 4000,使用防火墙将该端口关闭,那么别人就不能使用QQ了,当自己需要上网时只需开放该端口就可以了. 下面以我使用的“金山网镖6”进行说明,点击 ...