ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CSS流式布局 知识讲解

2021-06-30 09:54:18  阅读:207  来源: 互联网

标签:right border 10px 流式 width 讲解 margin CSS left


CSS的工作方式是浏览器逐行下载样式表,应用其可识别的属性,忽略其不支持的属性。本文将讲解CSS流式布局,分别从html结构、固定布局样式、将固定布局改为流式布局三个方面来阐述,感兴趣的小伙伴可以继续看下去。

 

192e03003d6e76373c63e6be0fd4b0c5.jpeg

 

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 >

 

<!-- 头部和导航 -->

 

<div >

 

<div >

 

<ul>

 

<li>

 

<a href="#">

 

首页

 

</a>

 

</li>

 

<li>

 

<a href="#">

 

导航一

 

</a>

 

</li>

 

</ul>

 

</div>

 

</div>

 

<!-- 侧边栏 -->

 

<div >

 

<p>这里是侧边栏</p>

 

</div>

 

<!-- 内容部分 -->

 

<div >

 

<p>这里是内容</p>

 

</div>

 

<!-- 页脚部分 -->

 

<div >

 

<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流式布局的讲解,大家都弄清楚了吗?

标签:right,border,10px,流式,width,讲解,margin,CSS,left
来源: https://blog.51cto.com/u_15128443/2956238

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有