在线客服
扫描二维码
下载博学谷APP
扫描二维码
关注博学谷微信公众号
CSS的工作方式是浏览器逐行下载样式表,应用其可识别的属性,忽略其不支持的属性。本文将讲解CSS流式布局,分别从html结构、固定布局样式、将固定布局改为流式布局三个方面来阐述,感兴趣的小伙伴可以继续看下去。

1、html结构
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus?">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<link rel="stylesheet" href="fluied.css">
<title>流式布局</title>
</head>
<body>
<div id="wrapper" class="clearfix">
<!-- 头部和导航 -->
<div id="header">
<div id="navigation">
<ul>
<li>
<a href="#">
首页
</a>
</li>
<li>
<a href="#">
导航一
</a>
</li>
</ul>
</div>
</div>
<!-- 侧边栏 -->
<div id="sidebar">
<p>这里是侧边栏</p>
</div>
<!-- 内容部分 -->
<div id="content">
<p>这里是内容</p>
</div>
<!-- 页脚部分 -->
<div id="footer">
<p>这里是页脚</p>
</div>
</div>
</body>
</html>
2、固定布局样式
@charset "utf-8";
* {
margin: 0;
padding: 0;
}
#wrapper {
margin-right: auto;
margin-left: auto;
width: 960px;
border: 1px solid red;
}
#header {
margin-right: 10px;
margin-left: 10px;
width: 940px;
}
#navgation {
padding-bottom: 25px;
margin-top: 26px;
margin-left: -10px;
padding-right: 10px;
padding-left: 10px;
width: 940px;
}
#navigation ul li {
display: inline-block;
}
#navigation ul li a {
text-decoration: none;
color: black;
}
#content {
margin-top: 58px;
margin-right: 10px;
float: right;
width: 698px;
border-bottom: 1px solid red;
height: 100px;
}
#sidebar {
border-right-color: #e8e8e8;
border-right-style: solid;
border-right-width: 2px;
margin-top: 58px;
padding-right: 10px;
margin-right: 10px;
margin-left: 10px;
float: left;
width: 220px;
border-bottom: 1px solid red;
height: 100px;
}
#footer {
float: left;
margin-top: 20px;
margin-right: 10px;
margin-left: 10px;
clear: both;
width: 940px;
}
.clearfix:before,
.clearfix:after {
content: "";
display: block;
clear: both;
width: 0;
height: 0;
visibility: hidden;
font-size: 0;
}
3、将固定布局改为流式布局
将固定像素宽度转换为对应的百分比宽度公式:
目标元素宽度 ÷ 上下文元素 = 百分比宽度
@charset "utf-8";
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
/*
* 初始状态下、1em = 16px;
* 设置了根元素的字体大小为62.5%,
*这时,1em = 10px
*/
font-size: 62.5%;
}
#wrapper {
margin-right: auto;
margin-left: auto;
width: 96%;
border: 1px solid red;
}
#header {
margin-right: 1.04166667%;
margin-left: 1.04166667%;
width: 97.9166667%;
border-bottom: 1px solid red;
font-size: 4.8em;
}
#navgation {
padding-bottom: 25px;
margin-top: 26px;
margin-left: -1.04166667%;
padding-right: 1.04166667%;
padding-left: 1.04166667%;
width: 100%;
}
#navigation ul li {
display: inline-block;
}
#navigation ul li a {
text-decoration: none;
color: black;
}
#content {
margin-top: 58px;
margin-right: 1.04166667%;
float: right;
width: 72.7083333%;
border-bottom: 1px solid red;
height: 100px;
font-size: 2em;
}
#sidebar {
border-right-color: #e8e8e8;
border-right-style: solid;
border-right-width: 2px;
margin-top: 58px;
padding-right: 1.04166667%;
margin-right: 1.04166667%;
margin-left: 1.04166667%;
float: left;
width: 22.7083333%;
border-bottom: 1px solid red;
height: 100px;
font-size: 2em;
}
#footer {
float: left;
margin-top: 20px;
margin-right: 1.04166667%;
margin-left: 1.04166667%;
clear: both;
width: 97.9166667%;
height: 100px;
font-size: 1.2em;
}
.clearfix:before,
.clearfix:after {
content: "";
display: block;
clear: both;
width: 0;
height: 0;
visibility: hidden;
font-size: 0;
}
以上就是CSS流式布局的讲解,大家都弄清楚了吗?
— 申请免费试学名额 —
在职想转行提升,担心学不会?根据个人情况规划学习路线,闯关式自适应学习模式保证学习效果
讲师一对一辅导,在线答疑解惑,指导就业!
相关推荐 更多
Web前端开发培训班学费多少钱?
Web前端开发培训就业班学费多少钱?如何甄别好的培训机构?参加Web前端培训后是否可以找到高薪的工作呢?大部分刚刚入行Web前端的小伙伴都会提出这些问题。下面小编就与大家一起探讨下这些问题。
13979
2019-12-05 15:47:45
2019年前端与移动开发培训就业方向多不多?
前端与移动开发是目前互联网中的热门就业方向。但是随着前端多元化的发展,企业对于人才的需求在不断增多的同时,对从业人员的技术水平也提升了要求。因此想通过简单的自学就找到高薪的前端工作不再想几年前那样容易。所以建议想同时前端与移动开发的朋友尽可能通过参加前端与移动开发培训完善并提升下自己的实力。那2019年前端与移动开发培训的就业方向多不多呢?
6761
2019-08-15 16:41:13
HTML5开发工具哪个好?前端必备工具推荐
HTML5作为前端开发中十分重要的部分,深受前端工程师的喜爱和欢迎。都说工欲善其事必先利其器。想要更好的完成在HTML5开发,好用的工具少不了。下面给大家推荐10款前端必备的HTML5开发工具,它们分别是Lungo、Animatron、DCloudHBuilder、mobl、Initializr、WebStorm、Notepad++、Dreamweaver、Eclipse和DevExtreme。
6990
2019-10-09 19:10:15
JavaScript基础语法规则
编程语言是人与机器交互语言。我们每天接触的汉语外语都有其特定的语法和规则,编程语言同样适用。每一种计算机语言都有自己的语法规则。只有按照语法规则才能写出符合要求的代码。下面我们就来了解一下JavaScript基础语法规则。
9238
2019-10-25 18:09:23
前端基础JavaScrip书籍推荐
相信对前端稍微有一些了解的人,都知道学习前端的三大基础,即HTML、CSS和JavaScrip,今天我们要讲的就是JavaScrip。关于JavaScript要学的内容是在太多了,尤其对于编程零基础的学习者来讲,学起来并不友好。因此本文将推荐给大家一些JavaScrip入门的书籍,大家可以先了解一些基础的语法知识,以打好Javascript能做一些的基础。
6857
2020-04-24 11:16:31
