目录

1.文档流

2.盒模型

3.盒模型--边框

4.盒模型--内边距

5.盒模型--外边距

6.盒子的水平布局

7.盒子的垂直布局

8.外边框的折叠

9.行内元素的盒模型

10.默认样式

11.练习

01.京东图片列表

02.京东左侧导航栏

03.网易新闻列表

12.盒子的尺寸

13.轮廓和圆角


1.文档流

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.box1{width: 100px;background-color: yellow;}.box2{width: 100px;background-color: red;}span{background-color: #bfa;}</style>
</head>
<body><!-- 文档流(normal flow)- 网页是一个多层的结构,一层摞着一层- 通过CSS可以分别为每一层来设置样式- 作为用户来讲只能看到最顶上一层- 这些层中,最底下的一层称为文档流,文档流是网页的基础我们所创建的元素默认都是在文档流中进行排列- 对于我们来元素主要有两个状态在文档流中不在文档流中(脱离文档流)- 元素在文档流中有什么特点:- 块元素- 块元素会在页面中独占一行(自上向下垂直排列)- 默认宽度是父元素的全部(会把父元素撑满)- 默认高度是被内容撑开(子元素)- 行内元素- 行内元素不会独占页面的一行,只占自身的大小- 行内元素在页面中左向右水平排列,如果一行之中不能容纳下所有的行内元素则元素会换到第二行继续自左向右排列(书写习惯一致)- 行内元素的默认宽度和高度都是被内容撑开--><div class="box1">我是div1</div><div class="box2">我是div2</div><span>我是span1</span><span>我是span2</span><span>我是span2</span><span>我是span2</span><span>我是span2</span><span>我是span2</span><span>我是span2</span><span>我是span2</span><span>我是span2</span><span>我是span2</span>
</body>
</html>

2.盒模型

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.box1{/* 内容区(content),元素中的所有的子元素和文本内容都在内容区中排列  内容区的大小由width 和 height两个属性来设置width 设置内容区的宽度height 设置内容区的高度          */width: 200px;height: 200px;background-color: #bfa;/* 边框(border),边框属于盒子边缘,边框里边属于盒子内部,出了边框都是盒子的外部边框的大小会影响到整个盒子的大小要设置边框,需要至少设置三个样式:边框的宽度 border-width边框的颜色 border-color边框的样式 border-style*/border-width: 10px;border-color: red;border-style: solid;}</style>
</head>
<body><!-- 盒模型、盒子模型、框模型(box model)- CSS将页面中的所有元素都设置为了一个矩形的盒子- 将元素设置为矩形的盒子后,对页面的布局就变成将不同的盒子摆放到不同的位置- 每一个盒子都由一下几个部分组成:内容区(content)内边距(padding)边框(border)外边距(margin)--><div class="box1"></div></body>
</html>

3.盒模型--边框

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.box1{width: 200px;height: 200px;background-color: #bfa;/* 边框边框的宽度 border-width边框的颜色 border-color边框的样式 border-style*//* border-width: 10px; 默认值,一般都是 3个像素border-width可以用来指定四个方向的边框的宽度值的情况四个值:上 右 下 左三个值:上 左右 下两个值:上下 左右一个值:上下左右除了border-width还有一组 border-xxx-widthxxx可以是 top right bottom left用来单独指定某一个边的宽度*//* border-width: 10px; *//* border-top-width: 10px;border-left-width: 30px; */color: red;/* border-color用来指定边框的颜色,同样可以分别指定四个边的边框规则和border-width一样border-color也可以省略不写,如果省略了则自动使用color的颜色值*//* border-color: orange red yellow green;border-color: orange; *//* border-style 指定边框的样式solid 表示实线dotted 点状虚线dashed 虚线double 双线border-style的默认值是none 表示没有边框*//* border-style: solid dotted dashed double;border-style: solid; *//* border-width: 10px;border-color: orange;border-style: solid; *//* border简写属性,通过该属性可以同时设置边框所有的相关样式,并且没有顺序要求除了border以外还有四个 border-xxxborder-topborder-rightborder-bottomborder-left*//* border: solid 10px orange; *//* border-top: 10px solid red;border-left: 10px solid red;border-bottom: 10px solid red; */border: 10px red solid;border-right: none;}</style>
</head>
<body><div class="box1"></div>
</body>
</html>

4.盒模型--内边距

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.box1{width: 200px;height: 200px;background-color: #bfa;border: 10px orange solid;/* 内边距(padding)- 内容区和边框之间的距离是内边距- 一共有四个方向的内边距:padding-toppadding-rightpadding-bottompadding-left- 内边距的设置会影响到盒子的大小- 背景颜色会延伸到内边距上一共盒子的可见框的大小,由内容区 内边距 和 边框共同决定,所以在计算盒子大小时,需要将这三个区域加到一起计算*//* padding-top: 100px;padding-left: 100px;padding-right: 100px;padding-bottom: 100px; *//* padding 内边距的简写属性,可以同时指定四个方向的内边距规则和border-width 一样*/padding: 10px 20px 30px 40px;padding: 10px 20px 30px ;padding: 10px 20px ;padding: 10px ;}.inner{width: 100%;height: 100%;background-color: yellow;}</style>
</head>
<body><div class="box1"><div class="inner"></div></div>
</body>
</html>

5.盒模型--外边距

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.box1{width: 200px;height: 200px;background-color: #bfa;border: 10px red solid;/* 外边距(margin)- 外边距不会影响盒子可见框的大小- 但是外边距会影响盒子的位置- 一共有四个方向的外边距:margin-top- 上外边距,设置一个正值,元素会向下移动margin-right- 默认情况下设置margin-right不会产生任何效果margin-bottom- 下外边距,设置一个正值,其下边的元素会向下移动margin-left- 左外边距,设置一个正值,元素会向右移动- margin也可以设置负值,如果是负值则元素会向相反的方向移动- 元素在页面中是按照自左向右的顺序排列的,所以默认情况下如果我们设置的左和上外边距则会移动元素自身而设置下和右外边距会移动其他元素- margin的简写属性margin 可以同时设置四个方向的外边距 ,用法和padding一样- margin会影响到盒子实际占用空间*//* margin-top: 100px;margin-left: 100px;margin-bottom: 100px; *//* margin-bottom: 100px; *//* margin-top: -100px; *//* margin-left: -100px; *//* margin-bottom: -100px; *//* margin-right: 0px; */margin: 100px;}.box2{width: 220px;height: 220px;background-color: yellow}</style>
</head>
<body><div class="box1"></div><div class="box2"></div>
</body>
</html>

6.盒子的水平布局

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.outer{width: 800px;height: 200px;border: 10px red solid;}.inner{/* width: auto;  width的值默认就是auto*/width: 200px;height: 200px;background-color: #bfa;margin-right: auto;margin-left: auto;/* margin-left: 100px;margin-right: 400px *//* 元素的水平方向的布局:元素在其父元素中水平方向的位置由以下几个属性共同决定“margin-leftborder-leftpadding-leftwidthpadding-rightborder-rightmargin-right一个元素在其父元素中,水平布局必须要满足以下的等式
margin-left+border-left+padding-left+width+padding-right+border-right+margin-right = 其父元素内容区的宽度 (必须满足)0 + 0 + 0 + 200 + 0 + 0 + 0 = 8000 + 0 + 0 + 200 + 0 + 0 + 600 = 800100 + 0 + 0 + 200 + 0 + 0 + 400 = 800100 + 0 + 0 + 200 + 0 + 0 + 500 = 800- 以上等式必须满足,如果相加结果使等式不成立,则称为过度约束,则等式会自动调整- 调整的情况:- 如果这七个值中没有为 auto 的情况,则浏览器会自动调整margin-right值以使等式满足- 这七个值中有三个值和设置为autowidthmargin-leftmaring-right- 如果某个值为auto,则会自动调整为auto的那个值以使等式成立0 + 0 + 0 + auto + 0 + 0 + 0 = 800  auto = 8000 + 0 + 0 + auto + 0 + 0 + 200 = 800  auto = 600200 + 0 + 0 + auto + 0 + 0 + 200 = 800  auto = 400auto + 0 + 0 + 200 + 0 + 0 + 200 = 800  auto = 400auto + 0 + 0 + 200 + 0 + 0 + auto = 800  auto = 300- 如果将一个宽度和一个外边距设置为auto,则宽度会调整到最大,设置为auto的外边距会自动为0- 如果将三个值都设置为auto,则外边距都是0,宽度最大- 如果将两个外边距设置为auto,宽度固定值,则会将外边距设置为相同的值所以我们经常利用这个特点来使一个元素在其父元素中水平居中示例:width:xxxpx;margin:0 auto;*/}</style>
</head>
<body><div class="outer"><div class="inner"></div></div></body>
</html>

7.盒子的垂直布局

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.outer{background-color: #bfa;height: 600px;/* 默认情况下父元素的高度被内容撑开*/}.inner{width: 100px;background-color: yellow;height: 100px;margin-bottom: 100px;}.box1{width: 200px;height: 200px;background-color: #bfa;/* 子元素是在父元素的内容区中排列的,如果子元素的大小超过了父元素,则子元素会从父元素中溢出使用 overflow 属性来设置父元素如何处理溢出的子元素可选值:visible,默认值 子元素会从父元素中溢出,在父元素外部的位置显示hidden 溢出内容将会被裁剪不会显示scroll 生成两个滚动条,通过滚动条来查看完整的内容auto 根据需要生成滚动条overflow-x: overflow-y:*/overflow: auto;}.box2{width: 100px;height: 400px;background-color: orange;}</style>
</head>
<body><!-- <div class="outer"><div class="inner"></div><div class="inner"></div></div> --><div class="box1">在我的后园,可以看见墙外有两株树,一株是枣树,还有一株也是枣树。 这上面的夜的天空,奇怪而高,我生平没有见过这样奇怪而高的天空。他仿佛要离开人间而去,使人们仰面不再看见。然而现在却非常之蓝,闪闪地䀹着几十个星星的眼,冷眼。他的口角上现出微笑,似乎自以为大有深意,而将繁霜洒在我的园里的野花草上。 我不知道那些花草真叫什么名字,人们叫他们什么名字。我记得有一种开过极细小的粉红花,现在还开着,但是更极细小了,她在冷的夜气中,瑟缩地做梦,梦见春的到来,梦见秋的到来,梦见瘦的诗人将眼泪擦在她最末的花瓣上,告诉她秋虽然来,冬虽然来,而此后接着还是春,蝴蝶乱飞,蜜蜂都唱起春词来了。她于是一笑,虽然颜色冻得红惨惨地,仍然瑟缩着。 枣树,他们简直落尽了叶子。先前,还有一两个孩子来打他们,别人打剩的枣子,现在是一个也不剩了,连叶子也落尽了。他知道小粉红花的梦,秋后要有春;他也知道落叶的梦,春后还是秋。他简直落尽叶子,单剩干子,然而脱了当初满树是果实和叶子时候的弧形,欠伸得很舒服。但是,有几枝还低亚着,护定他从打枣的竿梢所得的皮伤,而最直最长的几枝,却已默默地铁似的直刺着奇怪而高的天空,使天空闪闪地鬼䀹眼;直刺着天空中圆满的月亮,使月亮窘得发白。 鬼䀹眼的天空越加非常之蓝,不安了,仿佛想离去人间,避开枣树,只将月亮剩下。然而月亮也暗暗地躲到东边去了。而一无所有的干子,却仍然默默地铁似的直刺着奇怪而高的天空,一意要制他的死命,不管他各式各样地䀹着许多蛊惑的眼睛。 哇的一声,夜游的恶鸟飞过了。 我忽而听到夜半的笑声,吃吃地,似乎不愿意惊动睡着的人,然而四围的空气都应和着笑。夜半,没有别的人,我即刻听出这声音就在我嘴里,我也即刻被这笑声所驱逐,回进自己的房。灯火的带子也即刻被我旋高了。 后窗的玻璃上丁丁地响,还有许多小飞虫乱撞。不多久,几个进来了,许是从窗纸的破孔进来的。他们一进来,又在玻璃的灯罩上撞得丁丁地响。一个从上面撞进去了,他于是遇到火,而且我以为这火是真的。两三个却休息在灯的纸罩上喘气。那罩是昨晚新换的罩,雪白的纸,折出波浪纹的叠痕,一角还画出一枝猩红色的栀子。 猩红的栀子开花时,枣树又要做小粉红花的梦,青葱地弯成弧形了……我又听到夜半的笑声;我赶紧砍断我的心绪,看那老在白纸罩上的小青虫,头大尾小,向日葵子似的,只有半粒小麦那么大,遍身的颜色苍翠得可爱,可怜。 我打一个呵欠,点起一支纸烟,喷出烟来,对着灯默默地敬奠这些苍翠精致的英雄们。 一九二四年九月十五日。</div>
</body>
</html>

8.外边框的折叠

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.box1 , .box2{width: 200px;height: 200px;font-size: 100px;}/* 垂直外边距的重叠(折叠)- 相邻的垂直方向外边距会发生重叠现象- 兄弟元素- 兄弟元素间的相邻垂直外边距会取两者之间的较大值(两者都是正值)- 特殊情况:如果相邻的外边距一正一负,则取两者的和如果相邻的外边距都是负值,则取两者中绝对值较大的- 兄弟元素之间的外边距的重叠,对于开发是有利的,所以我们不需要进行处理- 父子元素- 父子元素间相邻外边距,子元素的会传递给父元素(上外边距)- 父子外边距的折叠会影响到页面的布局,必须要进行处理*/.box1{background-color: #bfa;/* 设置一个下外边距 */margin-bottom: 100px;}.box2{background-color: orange;/* 设置一个上外边距 */margin-top: 100px;}.box3{width: 200px;height: 200px;background-color: #bfa;/* padding-top: 100px; *//* border-top: 1px #bfa solid; */}.box4{width: 100px;height: 100px;background-color: orange;margin-top: 100px;}</style>
</head>
<body><div class="box3"><div class="box4"></div></div><!-- <div class="box1"></div><div class="box2"></div> --></body>
</html>

9.行内元素的盒模型

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.s1{background-color: yellow;/* 行内元素的盒模型- 行内元素不支持设置宽度和高度- 行内元素可以设置padding,但是垂直方向padding不会影响页面的布局- 行内元素可以设置border,垂直方向的border不会影响页面的布局- 行内元素可以设置margin,垂直方向的margin不会影响布局*//* width: 100px;height: 100px; *//* padding: 100px; *//* border: 100px solid red; */margin: 100px;}.box1{width: 200px;height: 200px;background-color: #bfa;}a{/* display 用来设置元素显示的类型可选值:inline 将元素设置为行内元素block 将元素设置为块元素inline-block 将元素设置为行内块元素 行内块,既可以设置宽度和高度又不会独占一行table 将元素设置为一个表格none 元素不在页面中显示visibility 用来设置元素的显示状态可选值:visible 默认值,元素在页面中正常显示hidden 元素在页面中隐藏 不显示,但是依然占据页面的位置*/display: block;visibility: hidden;width: 100px;height: 100px;background-color: orange;}</style>
</head>
<body><a href="javascript:;">超链接</a><a href="javascript:;">超链接</a><span class="s1">我是span</span><span class="s1">我是span</span><div class="box1"></div>
</body>
</html>

10.默认样式

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><!-- <link rel="stylesheet" href="./css/reset.css"> --><link rel="stylesheet" href="./css/normalize.css"><!-- 重置样式表:专门用来对浏览器的样式进行重置的reset.css 直接去除了浏览器的默认样式normalize.css 对默认样式进行了统一--><style>/* 默认样式:- 通常情况,浏览器都会为元素设置一些默认样式- 默认样式的存在会影响到页面的布局,通常情况下编写网页时必须要去除浏览器的默认样式(PC端的页面)*//* body{margin: 0;}p{margin: 0;}ul{margin: 0;padding: 0;/* 去除项目符号 * /list-style:none; } *//* *{margin: 0;padding: 0;} */.box1{width: 100px;height: 100px;border: 1px solid black;}</style>
</head>
<body><div class="box1"></div><p>我是一个段落</p>
<p>我是一个段落</p>
<p>我是一个段落</p><ul><li>列表项1</li><li>列表项2</li><li>列表项3</li>
</ul></body>
</html>

外部引入去除默认样式的两个css样式表:

reset.css

/* v2.0 | 20110126http://meyerweb.com/eric/tools/css/reset/ License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {margin: 0;padding: 0;border: 0;font-size: 100%;font: inherit;vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {display: block;
}
body {line-height: 1;
}
ol, ul {list-style: none;
}
blockquote, q {quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {content: '';content: none;
}
table {border-collapse: collapse;border-spacing: 0;
}

normalize.css

/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css *//* Document========================================================================== *//*** 1. Correct the line height in all browsers.* 2. Prevent adjustments of font size after orientation changes in iOS.*/html {line-height: 1.15; /* 1 */-webkit-text-size-adjust: 100%; /* 2 */
}/* Sections========================================================================== *//*** Remove the margin in all browsers.*/body {margin: 0;
}/*** Render the `main` element consistently in IE.*/main {display: block;
}/*** Correct the font size and margin on `h1` elements within `section` and* `article` contexts in Chrome, Firefox, and Safari.*/h1 {font-size: 2em;margin: 0.67em 0;
}/* Grouping content========================================================================== *//*** 1. Add the correct box sizing in Firefox.* 2. Show the overflow in Edge and IE.*/hr {box-sizing: content-box; /* 1 */height: 0; /* 1 */overflow: visible; /* 2 */
}/*** 1. Correct the inheritance and scaling of font size in all browsers.* 2. Correct the odd `em` font sizing in all browsers.*/pre {font-family: monospace, monospace; /* 1 */font-size: 1em; /* 2 */
}/* Text-level semantics========================================================================== *//*** Remove the gray background on active links in IE 10.*/a {background-color: transparent;
}/*** 1. Remove the bottom border in Chrome 57-* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.*/abbr[title] {border-bottom: none; /* 1 */text-decoration: underline; /* 2 */text-decoration: underline dotted; /* 2 */
}/*** Add the correct font weight in Chrome, Edge, and Safari.*/b,
strong {font-weight: bolder;
}/*** 1. Correct the inheritance and scaling of font size in all browsers.* 2. Correct the odd `em` font sizing in all browsers.*/code,
kbd,
samp {font-family: monospace, monospace; /* 1 */font-size: 1em; /* 2 */
}/*** Add the correct font size in all browsers.*/small {font-size: 80%;
}/*** Prevent `sub` and `sup` elements from affecting the line height in* all browsers.*/sub,
sup {font-size: 75%;line-height: 0;position: relative;vertical-align: baseline;
}sub {bottom: -0.25em;
}sup {top: -0.5em;
}/* Embedded content========================================================================== *//*** Remove the border on images inside links in IE 10.*/img {border-style: none;
}/* Forms========================================================================== *//*** 1. Change the font styles in all browsers.* 2. Remove the margin in Firefox and Safari.*/button,
input,
optgroup,
select,
textarea {font-family: inherit; /* 1 */font-size: 100%; /* 1 */line-height: 1.15; /* 1 */margin: 0; /* 2 */
}/*** Show the overflow in IE.* 1. Show the overflow in Edge.*/button,
input { /* 1 */overflow: visible;
}/*** Remove the inheritance of text transform in Edge, Firefox, and IE.* 1. Remove the inheritance of text transform in Firefox.*/button,
select { /* 1 */text-transform: none;
}/*** Correct the inability to style clickable types in iOS and Safari.*/button,
[type="button"],
[type="reset"],
[type="submit"] {-webkit-appearance: button;
}/*** Remove the inner border and padding in Firefox.*/button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {border-style: none;padding: 0;
}/*** Restore the focus styles unset by the previous rule.*/button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {outline: 1px dotted ButtonText;
}/*** Correct the padding in Firefox.*/fieldset {padding: 0.35em 0.75em 0.625em;
}/*** 1. Correct the text wrapping in Edge and IE.* 2. Correct the color inheritance from `fieldset` elements in IE.* 3. Remove the padding so developers are not caught out when they zero out*    `fieldset` elements in all browsers.*/legend {box-sizing: border-box; /* 1 */color: inherit; /* 2 */display: table; /* 1 */max-width: 100%; /* 1 */padding: 0; /* 3 */white-space: normal; /* 1 */
}/*** Add the correct vertical alignment in Chrome, Firefox, and Opera.*/progress {vertical-align: baseline;
}/*** Remove the default vertical scrollbar in IE 10+.*/textarea {overflow: auto;
}/*** 1. Add the correct box sizing in IE 10.* 2. Remove the padding in IE 10.*/[type="checkbox"],
[type="radio"] {box-sizing: border-box; /* 1 */padding: 0; /* 2 */
}/*** Correct the cursor style of increment and decrement buttons in Chrome.*/[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {height: auto;
}/*** 1. Correct the odd appearance in Chrome and Safari.* 2. Correct the outline style in Safari.*/[type="search"] {-webkit-appearance: textfield; /* 1 */outline-offset: -2px; /* 2 */
}/*** Remove the inner padding in Chrome and Safari on macOS.*/[type="search"]::-webkit-search-decoration {-webkit-appearance: none;
}/*** 1. Correct the inability to style clickable types in iOS and Safari.* 2. Change font properties to `inherit` in Safari.*/::-webkit-file-upload-button {-webkit-appearance: button; /* 1 */font: inherit; /* 2 */
}/* Interactive========================================================================== *//** Add the correct display in Edge, IE 10+, and Firefox.*/details {display: block;
}/** Add the correct display in all browsers.*/summary {display: list-item;
}/* Misc========================================================================== *//*** Add the correct display in IE 10+.*/template {display: none;
}/*** Add the correct display in IE 10.*/[hidden] {display: none;
}

11.练习

01.京东图片列表

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>图片列表</title><link rel="stylesheet" href="./css/reset.css"><style>/* 设置body的背景颜色 */body{background-color: antiquewhite}/* 设置外部ul的样式 */.img-list{/* 设置ul的宽度 */width: 190px;/* 设置ul的高度 */height: 470px;/* 裁剪溢出的内容 */overflow: hidden;/* 使ul在页面中居中(实际示例中不需要这么写) */margin: 50px auto;background-color: #F4F4F4;}/* 设置li的位置 */.img-list li:not(:last-child){margin-bottom: 9px;}/* 设置图片的大小 */.img-list img{width: 100%;}</style>
</head>
<body><!-- <div><a href="javascript:;"><img src="" alt=""></a><a href="javascript:;"><img src="" alt=""></a><a href="javascript:;"><img src="" alt=""></a></div> --><ul class="img-list"><li><a href="javascript:;"><img src="./img/01/1.jpg" alt=""></a></li><li><a href="javascript:;"><img src="./img/01/2.jpg" alt=""></a></li><li><a href="javascript:;"><img src="./img/01/3.jpg" alt=""></a></li></ul></body>
</html>

02.京东左侧导航栏

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>京东的左侧导航</title><link rel="stylesheet" href="./css/reset.css"><style>/* 设置body */body{/* 设置一个网页的背景,以使我们方便查看 */background-color: #bfa;}/* 设置菜单外部容器 */.left-nav{/* 设置宽度 */width: 190px;/* 设置高度 */height: 450px;/* 设置padding */padding: 10px 0;/* 设置一个背景颜色 */background-color: #fff;margin: 50px auto;}/* 设置菜单内部的item */.left-nav .item{height: 25px;/* 要让一个文字在父元素中垂直居中,只需将父元素的line-height设置为一个和父元素height一样的值 */line-height: 25px;/* 设置item的右内边距,将文字向内移动  */padding-left: 18px;/* 设置字体大小 */font-size: 12px;}/* 设置/的距离 */.item .line{padding: 0 2px;}/* 为item设置一个鼠标移入的状态 */.item:hover{background-color: #d9d9d9;}/* 设置超链接的样式 */.item a{/* 设置字体大小 */font-size: 14px;/* 设置字体的颜色 */color: #333;/* 去除下划线 */text-decoration: none;}/* 设置超链接的hover的样式 */.item a:hover{color: #c81623;}</style>
</head><body><!-- 创建一个外部的容器 nav(div) div(div) ul(li)  --><nav class="left-nav"><div class="item"><a href="#">家用电器</a></div><div class="item"><a href="#">手机</a><span class='line'>/</span><a href="#">运营商</a><span class='line'>/</span><a href="#">数码</a></div><div class="item"><a href="#">电脑</a><span class='line'>/</span><a href="#">办公</a></div><div class="item"><a href="#">家居</a><span class='line'>/</span><a href="#">家具</a><span class='line'>/</span><a href="#">家装</a><span class='line'>/</span><a href="#">厨具</a></div><div class="item"><a href="#">男装</a><span class='line'>/</span><a href="#">女装</a><span class='line'>/</span><a href="#">童装</a><span class='line'>/</span><a href="#">内衣</a></div><div class="item"><a href="#">美妆</a><span class='line'>/</span><a href="#">个护清洁</a><span class='line'>/</span><a href="#">宠物</a></div><div class="item"><a href="#">女鞋</a><span class='line'>/</span><a href="#">箱包</a><span class='line'>/</span><a href="#">钟表</a><span class='line'>/</span><a href="#">珠宝</a></div><div class="item"><a href="#">男鞋</a><span class='line'>/</span><a href="#">运动</a><span class='line'>/</span><a href="#">户外</a></div><div class="item"><a href="#">房产</a><span class='line'>/</span><a href="#">汽车</a><span class='line'>/</span><a href="#">汽车用品</a></div><div class="item"><a href="#">母婴</a><span class='line'>/</span><a href="#">玩具乐器</a></div><div class="item"><a href="#">食品</a><span class='line'>/</span><a href="#">酒类</a><span class='line'>/</span><a href="#">生鲜</a><span class='line'>/</span><a href="#">特产</a></div><div class="item"><a href="#">艺术</a><span class='line'>/</span><a href="#">礼品鲜花</a><span class='line'>/</span><a href="#">农资绿植</a></div><div class="item"><a href="#">医药保健</a><span class='line'>/</span><a href="#">计生情趣</a></div><div class="item"><a href="#">图书</a><span class='line'>/</span><a href="#">文娱</a><span class='line'>/</span><a href="#">电子书</a></div><div class="item"><a href="#">机票</a><span class='line'>/</span><a href="#">酒店</a><span class='line'>/</span><a href="#">旅游</a><span class='line'>/</span><a href="#">生活</a></div><div class="item"><a href="#">理财</a><span class='line'>/</span><a href="#">众筹</a><span class='line'>/</span><a href="#">白条</a><span class='line'>/</span><a href="#">保险</a></div><div class="item"><a href="#">安装</a><span class='line'>/</span><a href="#">维修</a><span class='line'>/</span><a href="#">清洗</a><span class='line'>/</span><a href="#">二手</a></div><div class="item"><a href="#">工业品</a></div></nav></body></html>

03.网易新闻列表

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>网易的新闻列表</title><link rel="stylesheet" href="./css/reset.css"><style>/* body{background-color: #bfa;} */a{/* 去除下划线 */text-decoration: none;}/* 设置容器的样式 */.news-wrapper{/* 设置宽度 */width: 300px;/* 设置高度 */height: 357px;/*设置居中  */margin: 50px auto;/* 设置背景颜色,显示轮廓 */background-color: #fff;/* 设置上边框 */border-top: 1px solid #ddd;}/* 设置news-title */.news-title{/* 为了边框和文字宽度一致,需要将h2转换为行内块元素 */display: inline-block;/* 设置高度 */height: 30px;/* 设置上边框  */border-top: 1px red solid;/* 通过margin-top将h2上移,盖住上边框 */margin-top: -1px;padding-top: 10px;}/* 设置title中超链接的样式 */.news-title a{/* 设置颜色 */color: #40406B;/* 设置文字的加粗效果 */font-weight: bold;}/* 设置图片容器的高度  */.news-img{height: 150px;}/* 设置图片的文字效果 */.news-img .img-title{/* 向上移动文字 */margin-top: -30px;/* 设置字体颜色 */color: #fff;/* 设置加粗 */font-weight: bold;/* 设置padding */padding-left: 30px;}/* 设置新闻列表 */.news-list{/* 设置上外边距 */margin-top: 20px;/* 设置左侧的padding *//* padding-left: 14px; *//* 设置项目符号 *//* list-style: square; */}/* 设置li */.news-list li{/*设置下外边距  */margin-bottom: 17px;}/* 通过before伪元素,来为每一个li添加项目符号 */.news-list li::before{content: '■';color: rgb(218, 218, 218);font-size: 12px;margin-right: 4px;}/* 设置li中文字 */.news-list li a{/* 设置字体大小 */font-size: 14px;/* 设置字体颜色 */color: #666;}/* 设置超链接的鼠标移入的样式 */.news-list li a:hover{color: red;}</style>
</head><body><!-- 创建新闻列表的外侧的容器 --><div class="news-wrapper"><!-- 创建一个标题标签 --><h2 class="news-title"><a href="#">体育</a></h2><!-- 创建一个图片的容器 --><div class="news-img"><a href="#"><img src="./img/03/1.jpeg" alt="费德勒"><!-- 创建图片标题 --><h3 class="img-title">费德勒首负迪米 扶额头不满发挥</h3></a></div><!-- 新闻列表 --><ul class="news-list"><li><a href="#">乔治:我爱LA 喜欢和LBJ一起打球</a></li><li><a href="#">格林:3年前降薪就在等KD 特制T恤嘲讽LBJ</a></li><li><a href="#">塔克4000双鞋让保罗羡慕嫉妒 乔丹被震惊</a></li><li><a href="#">CBA下季新赛制:常规赛4组循环 增至46轮</a></li></ul></div></body></html>

12.盒子的尺寸

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.box1{width: 100px;height: 100px;background-color: #bfa;padding: 10px;border: 10px red solid;/* 默认情况下,盒子可见框的大小由内容区、内边距和边框共同决定box-sizing 用来设置盒子尺寸的计算方式(设置width和height的作用)可选值:content-box 默认值,宽度和高度用来设置内容区的大小border-box 宽度和高度用来设置整个盒子可见框的大小width 和 height 指的是内容区 和 内边距 和 边框的总大小*/box-sizing: border-box;}</style>
</head>
<body><div class="box1"></div></body>
</html>

13.轮廓和圆角

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.box1{width: 200px;height: 200px;background-color: #bfa;/* box-shadow 用来设置元素的阴影效果,阴影不会影响页面布局 第一个值 水平偏移量 设置阴影的水平位置 正值向右移动 负值向左移动第二个值 垂直偏移量 设置阴影的水平位置 正值向下移动 负值向上移动第三个值 阴影的模糊半径第四个值 阴影的颜色*/box-shadow: 0px 0px 50px rgba(0, 0, 0, .3) ; /* outline 用来设置元素的轮廓线,用法和border一模一样轮廓和边框不同的点,就是轮廓不会影响到可见框的大小    */}/* .box1:hover{outline: 10px red solid;} */.box2{width: 200px;height: 200px;background-color: orange;/* border-radius: 用来设置圆角 圆角设置的圆的半径大小*//* border-top-left-radius:  *//* border-top-right-radius *//* border-bottom-left-radius:  *//* border-bottom-right-radius:  *//* border-top-left-radius:50px 100px; *//* border-radius 可以分别指定四个角的圆角四个值 左上 右上 右下 左下三个值 左上 右上/左下 右下 两个个值 左上/右下 右上/左下  *//* border-radius: 20px / 40px; *//* 将元素设置为一个圆形 */border-radius: 50%;}</style>
</head>
<body><!-- <div class="box1"></div> --><div class="box2"></div>
</body>
</html>

【web前端HTML5+CSS3】03CSS--layout(布局)之盒模型相关推荐

  1. 尚硅谷新版Web前端HTML5+CSS3知识点集合篇【p1-p8】

    尚硅谷新版Web前端HTML5+CSS3知识点集合笔记篇 尚硅谷新版Web前端HTML5+CSS3全套基础教程完整版(初学者零基础入门) p1(22:55) 一.软件的分类: 1.系统软件 -wind ...

  2. Web前端html5+css3前端开发入门学习笔记

    文章目录 前言 HTML 认识HTML 1. 网页组成和本质 2.了解浏览器 3.web标准 4.HTML感知 5.HTML骨架 6.编译软件vscode的简介和使用 7.注释 8.标签组成和关系 9 ...

  3. web前端html5+css3学习笔记(1)

    开启我的第一篇博客~~~ 记录学习html+css的笔记 目录 一.认识两位先驱 二.计算机的组成 1.硬件 2.软件 三.浏览器与内核 四.网页标准 五.HTML历史* 一.认识两位先驱 图灵:人工 ...

  4. 尚硅谷web前端HTML5+CSS3笔记

    目录 1尚硅谷-课程简介 2尚硅谷-网页简史 3尚硅谷-HTML简史 4尚硅谷-编写你的第一个网页 5尚硅谷-安装notepad++ 6尚硅谷-自结束标签和注释 7尚硅谷-标签中的属性 8尚硅谷-文档 ...

  5. web前端html5+css3学习笔记(3)——标签

    目录 一.排版标签 1.标题标签 2.段落标签 二.语义标签 三.块级元素和行内元素 1.块级元素 2.行内元素 四.文本标签 1.常用文本标签 2.不常用文本标签 五.图片标签 六.相对路径与绝对路 ...

  6. web前端+HTML5+CSS3学习笔记

    文章目录 HTML认知 网页的基本组成和本质 HTML初始概念 HTML标签学习 HTML基础 列表 表格 表单 语义化标签 字符实体 CSS基础 基础认知 选择器 文字字体 Emmet语法 CSS进 ...

  7. 【web前端HTML5+CSS3】08CSS--animation(动画) less

    目录 1.过渡 2.米兔过渡练习 3.动画 4.奔跑的少年练习 5.关键帧 6.变形平移 7.Z轴平移 8.旋转 9.鸭子表练习 10.复仇者联盟练习 11.缩放 12.less简介 13.less中 ...

  8. web前端html5+css3学习笔记(2)

    文章目录 目录 一.标签 二.HTML基本结构 三.vscode 1.插件 2.注释 3.文档声明 四.字符编码 五.设置语言 六.页面图标 一.标签 标签(也叫元素),需要小写 <marque ...

  9. 【web前端开发 | CSS】页面布局之盒子模型

    思维导图 文章目录 思维导图 1:边框 2:内边距 3:外边距 外边距合并 1. 相邻块元素垂直外边距的合并 2. 嵌套块元素垂直外边距的塌陷 所谓 盒子模型:就是把 HTML 页面中的布局元素看作是 ...

最新文章

  1. 前端进阶(三) webpack处理vue以及vue-cli脚手架环境
  2. 构造函数,析构函数,对象连的简单应用
  3. python装饰器_python装饰器完全指南之一
  4. java项目经验怎么写_模具工简历项目经验怎么写
  5. ab实验置信度_为什么您的Ab测试需要置信区间
  6. 前端学习(2536) request和response
  7. STM32F4 串口DMA
  8. vantUI 自定义引入iconfont图标(3种风格)- 案例篇
  9. mongodb 字符串转bson_MongoDB之bson的介绍
  10. 《用户体验要素——以用户为中心的产品设计》整理
  11. MyBatis中association,collection多表查询(resultMap高级映射)笔录
  12. 2021Java面试题及答案整理(最新汇总版)
  13. LDAP——实现用户统一登录管理
  14. LHDC、AAC、aptx、ldac、wha哪个更好,各有什么优缺点?
  15. 如何将arcgis中shape要素文件转为mapgis中点线面
  16. android对文件进行加密
  17. 小程序跳转公众号关注页面的两种方法
  18. 第一性原理:戳中问题本质的人是怎么思考的?
  19. 关于mp4格式转m3u8切片加密的方案调研
  20. Devops持续化集成

热门文章

  1. CCriticalSection
  2. multiMap遍历方法
  3. redis 操作5中数据类型
  4. GIT SSH配置已有秘钥
  5. centos 7 安装nagios
  6. autoform分析用什么计算机,AutoForm R6基本操作和模拟分析设置详细步骤!
  7. 使用计算机上存储的配置文件,Onedrive使用教程 如何存储文件到onedrive及管理
  8. CVPR2022论文速览--Vehicle trajectory prediction works, but not everywhere
  9. matlab生成任意波形发生器(AWG)所需波形文件程序
  10. Netfilter 网桥日志