W3C-Box model
什么叫盒子模型?有几种模式?

什么叫盒⼦模型?有⼏种模式?什么是盒⼦模型?把所有的⽹页元素都看成⼀个盒⼦,它具有: content,padding,border,margin 四个属性,这就是盒⼦模型。
盒⼦模型有⼏种模式?1、W3C标准盒⼦模型2、IE盒⼦模型W3C标准盒⼦模型标准模式下,⼀个块的宽度 = width+padding(内边距)+border(边框)+margin(外边距);W3C模型中: CSS中的宽(width)=内容(content)的宽 CSS中的⾼(height)=内容(content)的⾼IE盒⼦模型怪异模式下,⼀个块的宽度 = width+margin(外边距) (即怪异模式下,width包含了border以及padding)。
IE模型中: CSS中的宽(width)=内容(content)的宽+(border+padding)*2 CSS中的⾼(height)=内容(content)的⾼+(border+padding)*2CSS3 box-sizingbox-sizing:content-box||border-box||inheritbox-sizing:content-box; 将采⽤标准模式的盒⼦模型标准box-sizing:border-box; 将采⽤怪异模式的盒⼦模型标准box-sizing:inherit; 规定应从⽗元素继承 box-sizing 属性的值。
总结IE5.5及更早的版本使⽤的是IE盒模型。
IE6及其以上的版本在标准兼容模式下使⽤的是W3C的盒模型标准。
我们说这是⼀个好消息因为这意味着此盒模型问题只会出现在IE5.5及其更早的版本中。
只要为⽂档设置⼀个DOCTYPE,就会使得IE遵循标准兼容模式的⽅式⼯作。
兼容ie6的十条修复

我们知道ie会在一段时间内仍然流行,但是我们仍然可以支持浏览器并且避免hacks和条件css吗?这里有十条使用有效的html和css代码修复可以兼容ie6常见的问题。
1、使用一个声明你必须经常在html网页头部放置一个声明,推荐使用严格的标准。
例如或者xhtml使用最后你需要是ie6进入兼容模式,这已经足够兼容的了。
2、使用position: relative设置一个标签position: relative可以解决很多问题,特别是曾经有过看不见的经历或者奇怪布局的框架。
明显的,你需要小心,绝对位置放置的子元素是否都参照找到新位置。
3、为浮动元素使用display:inline浮动元素会有一个著名的ie6双边距margin bug。
假如你设置了左边距5px但实际上得到了10px左边距。
display:inline可以解决这个问题,尽管它不是必需的,但是css仍然有效。
4、设置元素启动hasLayout大部分ie6(ie7)的渲染问题都可以通过起来元素的hasLayout属性来兼容。
这是ie内置的设定,确定一个内容块相对其它内容块是有界限和位置的。
当你需要设置一个行内元素例如一个连接变成块状元素或者是透明效果,设置hasLayout也是必须的。
5、修复重复字符的bug复杂的布局会触发一个bug:浮动对象的最后字符会出现在已经清除浮动的元素后面。
这里有几种解决的办法,部分是理想的,并且一些测试和出错是必须的。
a、确保浮动元素都使用:display:inline;b、最后一个浮动元素使用margin-right:-3px;c、在浮动对象最后一个元素后使用一个条件注释。
例如这里输入注释…<![endif]d、在容器内的最后使用一个div空标签(它也必须设置90%宽度甚至更小)6、使用a标签完成可点击和hover原理Ie6只支持a标签的css定义hover效果你可以使用它去控制javascript启动的widgets,使得他们仍然保持键盘操作。
CSS 框模型概述

CSS 框模型概述CSS 框模型 (Box Model) 规定了元素框处理元素内容、内边距、边框 和 外边距 的方式。
规定了元素框处理元素内容、内边距、 的方式。
一、CSS 框模型概述元素框的最内部分是实际的内容,直接包围内容的是内边距。
内边距呈现了元素的背景。
内边距的边缘是 边框。
边框以外是外边距,外边距默认是透明的,因此不会遮挡其后的任何元素。
提示: 提示:背景应用于由内容和内边距组成的区域。
内边距、边框和外边距都是可选的,默认值是零。
但是,许多元素将由用户代理样式表设置外边距和内边 距。
可以通过将元素的 margin 和 padding 设置为零来覆盖这些浏览器样式。
这可以分别进行,也可以 使用通用选择器对所有元素进行设置:* {margin: 0; padding: 0; }在 CSS 中,width 和 height 指的是内容区域的宽度和高度。
增加内边距、边框和外边距不会影响内容 区域的尺寸,但是会增加元素框的总尺寸。
假设框的每个边上有 10 个像素的外边距和 5 个像素的内边距。
如果希望这个元素框达到 100 个像素, 就需要将内容的宽度设置为 70 像素,请看下图:#box { width: 70px; margin: 10px; padding: 5px; }提示: 提示:内边距、边框和外边距可以应用于一个元素的所有边,也可以应用于单独的边。
提示: 提示:外边距可以是负值,而且在很多情况下都要使用负值的外边距。
浏览器兼容性 浏览器兼容性一旦为页面设置了恰当的 DTD,大多数浏览器都会按照上面的图示来呈现内容。
然而 IE 5 和 6 的呈现 却是不正确的。
根据 W3C 的规范, 元素内容占据的空间是由 width 属性设置的, 而内容周围的 padding 和 border 值是另外计算的。
不幸的是,IE5.X 和 6 在怪异模式中使用自己的非标准模型。
这些浏览器 的 width 属性不是内容的宽度,而是内容、内边距和边框的宽度的总和。
盒子模型详解

盒⼦模型详解盒⼦模型盒⼦模型,英⽂即box model。
⽆论是div、span、还是a都是盒⼦。
但是,图⽚、表单元素⼀律看作是⽂本,它们并不是盒⼦。
这个很好理解,⽐如说,⼀张图⽚⾥并不能放东西,它⾃⼰就是⾃⼰的内容。
⼀个盒⼦中主要的属性就5个:width、height、padding、border、margin。
如下:width和height:内容的宽度、⾼度(不是盒⼦的宽度、⾼度)。
padding:内边距。
border:边框。
margin:外边距。
盒⼦模型的⽰意图:代码演⽰:上⾯这个盒⼦,width:200px; height:200px; 但是真实占有的宽⾼是302*302。
这是因为还要加上padding、border。
注意:宽度和真实占有宽度,不是⼀个概念!来看下⾯这例⼦。
我们⽬前所学习的知识中,以标准盒⼦模型为准。
标准盒⼦模型:IE盒⼦模型:上图显⽰:在 CSS 盒⼦模型 (Box Model) 规定了元素处理元素的⼏种⽅式:width和height:内容的宽度、⾼度(不是盒⼦的宽度、⾼度)。
padding:内边距。
border:边框。
margin:外边距。
CSS盒模型和IE盒模型的区别:在标准盒⼦模型中,width 和 height 指的是内容区域的宽度和⾼度。
增加内边距、边框和外边距不会影响内容区域的尺⼨,但是会增加元素框的总尺⼨。
IE盒⼦模型中,width 和 height 指的是内容区域+border+padding的宽度和⾼度。
注:Android中也有margin和padding的概念,意思是差不多的,如果你会⼀点Android,应该⽐较好理解吧。
区别在于,Android中没有border这个东西,⽽且在Android中,margin并不是控件的⼀部分,我觉得这样做更合理⼀些,呵呵。
<body>标签有必要强调⼀下。
很多⼈以为<body>标签占据的是整个页⾯的全部区域,其实是错误的,正确的理解是这样的:整个⽹页最⼤的盒⼦是<document>,即浏览器。
margin属性

margin属性margin在中文中我们翻译成外边距或者外补白(本文中引用外边距)。
他是元素盒模型(box model)的基础属性。
一、margin的基本特性margin属性包括margin-top,margin-right,margin-bottom,margin-left,margin,可以用来设置box的margin area。
属性margin可以用来同时设置box的四边外边距,而其他的margin属性只能设置其自各的外边距。
margin属性可以应用于几乎所有的元素,除了表格显示类型(不包括table-caption, table and inline-table)的元素,而且垂直外边距对非置换内联元素(non-replaced inline element)不起作用。
或许有朋友对非置换元素(non-replaced element)有点疑惑,稍微帮助大家理解一下。
非置换元素,W3C中没有给出明确的定义,但我们从字面可以理解到,非置换元素对应着置换元素(replaced element),也就是说我们搞懂了置换元素的含义,就懂了非置换元素。
置换元素,W3C中给出了定义:引用:“An element that is outside the scope of the CSS formatter, such as an image, embedded docu ment, or applet”从定义中我们可以理解到,置换元素(replaced element)主要是指img,input,textarea,select,object等这类默认就有CSS格式化外表范围的元素。
进而可知,非置换元素(non-replaced element)就是除了img,input,textarea,select,object等置换元素以外的元素。
margin始终是透明的。
二、margin的基本写法外边距的margin-width的值类型有:auto | length | percentagepercentage:百分比是由被应用box的containing block(注:一个元素的containing block 是该元素产生的box(es)在计算位置和大小时参考的一个矩形,详细阅读可看:《Containing Block》)的大小所决定。
epub的制作--CSS的使用方式

epub的制作--CSS的使用方式一、前言什么是CSS? 先看一下同一个epub在不同的阅读器上的呈现效果。
同一个档案,在书苑中的阅读器中和calibre中的呈现方式。
由于繁体字的笔画较多,在书苑中的阅读经验并不是很好。
因此,适当的加大字与字、行与行之间的距离是有必要的。
请再检查calibre中的阅读效果。
测试用的档案中又加上了背景颜色、文字颜色的设定,虽然书苑中的阅读器并不能呈现这种效果,但是在支持较多的CSS阅读器上,你可以看到变化的情形。
这就是CSS,用来设定文字、图片…在epub上的呈现方式。
目前,epub书籍中的样式设定是藉由CSS(cascading style sheets, 连接样式表)来设定的。
CSS,由W3C (world wideweb consortium)所公布,主要的用途是在加强网页中文字控制及版面编辑,它是用来扩充 HTML 的功能。
由于epub 仍是网页的格式,因此,CSS语法也可以使用在epub书籍的排版上。
但是,目前CSS在epub的应用上,仍是以段落样式为主,主要是设定边界、首行缩排、行距、文字对齐..等基本的排版功能,使用上仍有其不足。
甚至于,在现在的epub 书籍中,能找到具有文绕图效果的eupb书籍还是不容易。
这并不是开发水平的问题,而是目前的阅读器对CSS的支持仍有限。
但是,随着epub3标准的普及,未来的epub书籍,不仅对CSS有更大的支持性,而且,在epub上,也能利用javaScript、jQuery等语法来设计互动的效果。
因此,在未来的epub书籍中,大量的使用CSS语法是指日可待的。
CSS的学习并不容易,因为它包含了大量的语法。
幸运的是,如果你使用支持intelliSense功能的编辑器,例如:DreamWeaver,撰写CSS并不是难事。
因此,大量的属性并不需要你去记忆…相反的,在开始学习CSS时,你要将重点放在使用的方式上,这才是学习的重点。
border-box——一种改变盒子尺寸的方法

border-box——⼀种改变盒⼦尺⼨的⽅法语法:box-sizing:content-box|border-box|padding-boxIE6中的传统盒⼦模型: CSS样式声明的 width 和 hieght 包含 content、padding 和 border。
这就是 border-box 盒⼦模型。
W3C 的盒⼦模型是 content-box,即CSS样式声明的⾼度和宽度是 content 的尺⼨。
padding-box 盒⼦样式声明中的⾼度是和宽度是 paddin和content的宽度和⾼度。
如何⽤好他们?W3C的盒⼦是反⾃觉的,也就说我们把⼀样东西放到⼀个盒⼦⾥,再把盒⼦放到仓库⾥,东西占的尺⼨是盒⼦的尺⼨,⽽不是东西的尺⼨。
border-box 不反⾃觉。
很多现代框架如bootstrap 就是这么处理的。
流式布局和border-box:这个属性⼴泛⽤于流式布局,尤其是以百分数为基础的布局。
想象⼀个场景:导航栏 有5个项⽬,每个项⽬占 20% 的宽度,加上⼀条⽤于分割他们的固定尺⼨的边框,1nav li{2width:20%;3display:inline-block;4border-left:0.25em solid #fff;5 }那个第五个项⽬将换⾏。
为了避免它换⾏,我们告诉浏览器⽤ border-box 去计算盒⼦宽度。
nav li {box-sizing:border-box;width:20%;display:inline-block;border-left:0.25em solid #fff;}⽤ border-box 统⼀表单控件的尺⼨不同浏览器对表单控件的处理有的⽤ content-box,有的⽤ border-box,如input type="sumbmit" VS select。
⽤ border-box 就统⼀处理了。
padding-box 很不常见,只有FF⽀持。
css属性列表和属性值含义

css属性列表和属性值含义css属性列表属性名称字体属性(Font)font-familyfont-stylefont-variantfont-weightfont-size颜色和背景属性ColorBackground-color Background-image Background-repeat Background-attachment Background-position文本属性Word-spacingLetter-spacingText-decoration Vertical-alignText-transformText-alignText-indentLine-height边距属性Margin-topMargin-rightMargin-bottomMargin-leftMargin 属性含义使用什么字体字体是否斜体是否用小体大写字体的粗细字体的大小定义前景色定义背景色定义背景图案重复方式设置滚动初始位置单词之间的间距字母之间的间距文字的装饰样式垂直方向的位置文本转换对齐方式首行的缩进方式文本的行高分别设置上右下左,一个值属性值所有的字体Normal、italic、obliqueNormal、small-capsNormal、bold、bolder、lithter等Absolute-size、relative-size、length、percentage等颜色颜色路径Repeat-x、repeat-y、no-repeatScroll、FixedPercentage、length、top、left、right、bottom等Normal <length>同上None|underline|overline|line-through|blinkBaseline|sub|super|top|text-top|middle|bottom|text-bottom|Capitalize|uppercase|lowercase|noneLeft|right|center|justify<length>|<percentage>Normal|<number>|<length>|<percentage>Length|percentage|auto同上同上同上填充距属性Padding-top Padding-right Padding-bottom Padding-left Padding边框属性Border-top-width Border-right-width Border-bottom-width Border-left-width Border-width Border-color Border-style Border-topBorder-rightBorder-bottom Border-leftWidthHeightFloatClear分级属性DisplayWhite-spaceList-style-typeList-style-imageList-style-position List-style鼠标(Cursor)属性设置全部顶端边距右侧边距底端边距左侧边距同Margin顶端填充距右侧填充距底端填充距左侧填充距顶端边框宽度右侧边框宽度底端边框宽度左侧边框宽度一次定义宽度设置边框颜色设置边框样式一次定义顶端一次定义右侧一次定义底端一次定义左侧定义宽度属性定义高度属性文字环绕哪一边环绕定义是否显示怎样处理空白加项目编号加图案第二行起始位置一次定义列表自动定位“十”字默认指针Length|percentage同上同上同上同MarginThin|medium|thick|length同上同上同上同上ColorNone|dotted|dashed|dash|solid|double|groove|ridge|inset|outset等Border-top-width|color等同上同上同上Length|percentage|autoLength|autoLeft|right|noneLeft|right|none|bothBlock、inline、list-item、noneNormal、pre、nowrapDisc、circle、square等<url>|noneInside、outside<keyword>|<position> |<url>AutoCrosshairDefaultHandMovee-resizeNe-resizeNw-resizen-resize手形移动箭头朝右方箭头朝右上方箭头朝左上方箭头朝上方箭头朝右下方箭头朝左下方箭头朝下方箭头朝左方文本“I”形等待帮助Se-resize Sw-resize s-resize w-resize TextWait HelpCSS属性:1、媒体(Media)类型样式单的一个最重要的特点就是它可以作用于多种媒体,比如页面、屏幕、电子合成器等等。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
8 Box modelContents∙8.1 Box dimensions∙8.2 Example of margins, padding, and borders8.3 Margin properties: 'margin-top', 'margin-right', 'margin-bottom', 'margin-left', and 'margin'o8.3.1 Collapsing margins∙8.4 Padding properties: 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', and 'padding'8.5 Border propertieso8.5.1 Border width: 'border-top-width', 'border-right-width','border-bottom-width', 'border-left-width', and 'border-width'o8.5.2 Border color: 'border-top-color', 'border-right-color','border-bottom-color', 'border-left-color', and 'border-color'o8.5.3 Border style: 'border-top-style', 'border-right-style','border-bottom-style', 'border-left-style', and 'border-style'o8.5.4 Border shorthand properties: 'border-top', 'border-right','border-bottom', 'border-left', and 'border'∙8.6 The box model for inline elements in bidirectional contextThe CSS box model describes the rectangular boxes that are generated for elements in the document tree and laid out according to the visual formatting model.8.1 Box dimensionsEach box has a content area (e.g., text, an image, etc.) and optional surrounding padding, border, and margin areas; the size of each area is specified by properties defined below. The following diagram shows how these areas relate and the terminology used to refer to pieces of margin, border, and padding:The margin, border, and padding can be broken down into top, right, bottom, and left segments (e.g., in the diagram, "LM" for left margin, "RP" for right padding, "TB" for top border, etc.).The perimeter of each of the four areas (content, padding, border, and margin) is called an "edge", so each box has four edges:content edge or inner edgeThe content edge surrounds the rectangle given by the width and height of the box, which often depend on the element's rendered content. The four content edges define the box's content box.padding edgeThe padding edge surrounds the box padding. If the padding has 0 width, the padding edge is the same as the content edge. The four padding edges define the box's padding box.border edgeThe border edge surrounds the box's border. If the border has 0 width, the border edge is the same as the padding edge. The four border edges define the box's border box.margin edge or outer edgeThe margin edge surrounds the box margin. If the margin has 0 width, the margin edge is the same as the border edge. The four margin edges define the box's margin box.Each edge may be broken down into a top, right, bottom, and left edge.The dimensions of the content area of a box — the content width and content height —depend on several factors: whether the element generating the box has the 'width' or 'height' property set, whether the box contains text or other boxes, whether the box is a table, etc. Box widths and heights are discussed in the chapter on visual formatting model details.The background style of the content, padding, and border areas of a box is specified by the 'background' property of the generating element. Margin backgrounds are always transparent.8.2 Example of margins, padding, and bordersThis example illustrates how margins, padding, and borders interact. The example HTML document:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"><HTML><HEAD><TITLE>Examples of margins, padding, and borders</TITLE><STYLE type="text/css">UL {background: yellow;margin: 12px 12px 12px 12px;padding: 3px 3px 3px 3px;/* No borders set */}LI {color: white; /* text color is white */background: blue; /* Content, padding will be blue */margin: 12px 12px 12px 12px;padding: 12px 0px 12px 12px; /* Note 0px padding right */list-style: none /* no glyphs before a list item *//* No borders set */}LI.withborder {border-style: dashed;border-width: medium; /* sets border width on all sides */border-color: lime;}</STYLE></HEAD><BODY><UL><LI>First element of list<LI class="withborder">Second element of list isa bit longer to illustrate wrapping.</UL></BODY></HTML>results in a document tree with (among other relationships) a UL element that has two LI children.The first of the following diagrams illustrates what this example would produce. The second illustrates the relationship between the margins, padding, and borders of the UL elements and those of its children LI elements. (Image is not to scale.)Note that:∙The content width for each LI box is calculated top-down; the containing block for each LI box is established by the UL element.∙The margin box height of each LI box depends on its content height, plus top and bottom padding, borders, and margins. Note that vertical margins between the LI boxes collapse.∙The right padding of the LI boxes has been set to zero width (the 'padding' property). The effect is apparent in the second illustration.∙The margins of the LI boxes are transparent — margins are always transparent —so the background color (yellow) of the UL padding and content areas shines through them.∙The second LI element specifies a dashed border (the 'border-style' property). 8.3 Margin properties: 'margin-top', 'margin-right', 'margin-bottom', 'margin-left', and'margin'Margin properties specify the width of the margin area of a box. The 'margin' shorthand property sets the margin for all four sides while the other margin properties only set their respective side. These properties apply to all elements, but vertical margins will not have any effect on non-replaced inline elements.The properties defined in this section refer to the <margin-width> value type, which may take one of the following values:<length>Specifies a fixed width.<percentage>The percentage is calculated with respect to the width of the generated box's containing block. Note that this is true for 'margin-top' and 'margin-bottom' as well. If the containing block's width depends on this element, then the resulting layout is undefined in CSS 2.1.autoSee the section on calculating widths and margins for behavior.Negative values for margin properties are allowed, but there may beimplementation-specific limits.'margin-top', 'margin-bottom'Value:<margin-width>| inheritInitial:0all elements except elements with table display types other than Applies to:table-caption, table and inline-tableInherited:noPercentages:refer to width of containing blockMedia:visualComputedthe percentage as specified or the absolute lengthvalue:These properties have no effect on non-replaced inline elements.'margin-right', 'margin-left'Value:<margin-width>| inheritInitial:0all elements except elements with table display types other than Applies to:table-caption, table and inline-tableInherited:noPercentagesrefer to width of containing block:Media:visualComputedthe percentage as specified or the absolute lengthvalue:These properties set the top, right, bottom, and left margin of a box.h1 { margin-top: 2em }'margin'Value:<margin-width>{1,4} | inheritInitial:see individual propertiesall elements except elements with table display types other than Applies to:table-caption, table and inline-tableInherited:noPercentagesrefer to width of containing block:Media:visualComputedsee individual propertiesvalue:The 'margin' property is a shorthand property for setting 'margin-top', 'margin-right', 'margin-bottom', and 'margin-left' at the same place in the style sheet.If there is only one value, it applies to all sides. If there are two values, the top and bottom margins are set to the first value and the right and left margins are set to the second. If there are three values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third. If there are four values, they apply to the top,right, bottom, and left, respectively.body { margin: 2em } /* all margins set to 2em */body { margin: 1em 2em } /* top & bottom = 1em, right & left = 2em */body { margin: 1em 2em 3em } /* top=1em, right=2em, bottom=3em, left=2em */The last rule of the example above is equivalent to the example below:body {margin-top: 1em;margin-right: 2em;margin-bottom: 3em;margin-left: 2em; /* copied from opposite side (right) */}8.3.1 Collapsing marginsIn this specification, the expression collapsing margins means that adjoining margins (no non-empty content, padding or border areas or clearance separate them) of two or more boxes (which may be next to one another or nested) combine to form a single margin.In CSS 2.1, horizontal margins never collapse.Vertical margins may collapse between certain boxes:Two or more adjoining vertical margins of block boxes in the normal flow collapse.The resulting margin width is the maximum of the adjoining margin widths. In the caseof negative margins, the maximum of the absolute values of the negative adjoining margins is deducted from the maximum of the positive adjoining margins. If there are no positive margins, the absolute maximum of the negative adjoining margins is deducted from zero. Note. Adjoining boxes may be generated by elements that are not related as siblings or ancestors.∙Vertical margins between a floated box and any other box do not collapse (not even between a float and its in-flow children).∙Vertical margins of elements that establish new block formatting contexts (such as floats and elements with 'overflow' other than 'visible') do not collapse with their in-flow children.∙Margins of absolutely positioned boxes do not collapse (not even with their in-flow children).∙Margins of inline-block elements do not collapse (not even with their in-flow children).∙If the top and bottom margins of a box are adjoining, then it is possible for margins to collapse through it. In this case, the position of the element depends on its relationship with the other elements whose margins are being collapsed.o If the element's margins are collapsed with its parent's top margin, the top border edge of the box is defined to be the same as the parent's.o Otherwise, either the element's parent is not taking part in the margin collapsing, or only the parent's bottom margin is involved. The position of the element's top border edge is the same as it would have been if the elementhad a non-zero bottom border.An element that has had clearance applied to it never collapses its top margin with its parent block's bottom margin.Note that the positions of elements that have been collapsed through have no effect on the positions of the other elements with whose margins they are being collapsed; the top border edge position is only required for laying out descendants of these elements.Margins of the root element's box do not collapse.The bottom margin of an in-flow block-level element is always adjoining to the top margin of its next in-flow block-level sibling, unless that sibling has clearance.The top margin of an in-flow block-level element is adjoining to its first in-flow block-level child's top margin if the element has no top border, no top padding, and the child has no clearance.The bottom margin of an in-flow block-level element with a 'height' of 'auto' is adjoining to its last in-flow block-level child's bottom margin if the element has no bottom padding or border.An element's own margins are adjoining if the 'min-height' property is zero, and it has neither top or bottom borders nor top or bottom padding, and it has a 'height' of either 0 or 'auto', and it does not contain a line box, and all of its in-flow children's margins (if any) are adjoining.When an element's own margins collapse, and that element has had clearance applied to it, its top margin collapses with the adjoining margins of subsequent siblings but that resulting margin does not collapse with the bottom margin of the parent block.Collapsing is based on the used value of 'padding', 'margin', and 'border' (i.e., after resolving any percentages). The collapsed margin is calculated over the used value of the various margins.Please consult the examples of margin, padding, and borders for an illustration of collapsed margins.8.4 Padding properties: 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', and 'padding'The padding properties specify the width of the padding area of a box. The 'padding' shorthand property sets the padding for all four sides while the other padding properties only set their respective side.The properties defined in this section refer to the <padding-width>value type, which may take one of the following values:<length>Specifies a fixed width.<percentage>The percentage is calculated with respect to the width of the generated box's containing block, even for 'padding-top' and 'padding-bottom'. If the containing block's width depends on this element, then the resulting layout is undefined in CSS 2.1. Unlike margin properties, values for padding values cannot be negative. Like margin properties, percentage values for padding properties refer to the width of the generated box's containing block.'padding-top', 'padding-right', 'padding-bottom', 'padding-left'Value:<padding-width>| inheritInitial:0all elements except table-row-group, table-header-group, Applies to:table-footer-group, table-row, table-column-group and table-column Inherited:noPercentagesrefer to width of containing block:Media:visualComputedthe percentage as specified or the absolute lengthvalue:These properties set the top, right, bottom, and left padding of a box.blockquote { padding-top: 0.3em }'padding'Value:<padding-width>{1,4} | inheritInitial:see individual propertiesall elements except table-row-group, table-header-group, Applies to:table-footer-group, table-row, table-column-group and table-column Inherited:noPercentagesrefer to width of containing block:Media:visualComputedsee individual propertiesvalue:The 'padding' property is a shorthand property for setting 'padding-top', 'padding-right', 'padding-bottom', and 'padding-left' at the same place in the style sheet.If there is only one value, it applies to all sides. If there are two values, the top and bottom paddings are set to the first value and the right and left paddings are set to the second. If there are three values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third. If there are four values, they apply to the top, right, bottom, and left, respectively.The surface color or image of the padding area is specified via the 'background' property: h1 {background: white;padding: 1em 2em;}The example above specifies a '1em' vertical padding ('padding-top' and 'padding-bottom') and a '2em' horizontal padding ('padding-right' and 'padding-left'). The 'em' unit is relative to the element's font size: '1em' is equal to the size of the font in use.8.5 Border propertiesThe border properties specify the width, color, and style of the border area of a box. These properties apply to all elements.Note.Notably for HTML, user agents may render borders for certain user interfaceelements (e.g., buttons, menus, etc.) differently than for "ordinary" elements.8.5.1 Border width: 'border-top-width', 'border-right-width', 'border-bottom-width','border-left-width', and 'border-width'The border width properties specify the width of the border area. The properties defined in this section refer to the <border-width> value type, which may take one of the following values:thinA thin border.mediumA medium border.thickA thick border.<length>The border's thickness has an explicit value. Explicit border widths cannot be negative.The interpretation of the first three values depends on the user agent. The following relationships must hold, however:'thin' <='medium' <= 'thick'.Furthermore, these widths must be constant throughout a document.'border-top-width', 'border-right-width', 'border-bottom-width', 'border-left-width'Value:<border-width>| inheritInitial:medium Applies to:all elements Inherited:no Percentages:N/A Media:visualComputed value:absolute length; '0' if the border style is 'none' or 'hidden'These properties set the width of the top, right, bottom, and left border of a box.'border-width'Value:<border-width>{1,4} |inheritInitial:see individual propertiesApplies to:all elementsInherited:noPercentages:N/AMedia:visualComputedvalue:see individual propertiesThis property is a shorthand property for setting 'border-top-width', 'border-right-width', 'border-bottom-width', and 'border-left-width' at the same place in the style sheet.If there is only one value, it applies to all sides. If there are two values, the top and bottom borders are set to the first value and the right and left are set to the second. If there arethree values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third. If there are four values, they apply to the top, right, bottom, and left, respectively.In the examples below, the comments indicate the resulting widths of the top, right, bottom, and left borders:h1 { border-width: thin } /* thin thin thin thin */h1 { border-width: thin thick } /* thin thick thin thick */h1 { border-width: thin thick medium } /* thin thick medium thick */8.5.2 Border color: 'border-top-color', 'border-right-color', 'border-bottom-color','border-left-color', and 'border-color'The border color properties specify the color of a box's border.'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color'Value:<color>| transparent | inheritInitial:the value of the 'color' propertyApplies to:all elementsInherited:noPercentages: N/AMedia:visualComputed value:when taken from the 'color' property, the computed value of 'color'; otherwise, as specified'border-color'[ <color> | transparent ]{1,4} |Value:inheritInitial:see individual propertiesApplies to:all elementsInherited:noPercentages:N/AMedia:visualComputedsee individual propertiesvalue:The 'border-color' property sets the color of the four borders. Values have the following meanings:<color>Specifies a color value.transparentThe border is transparent (though it may have width).The 'border-color' property can have from one to four values, and the values are set on the different sides as for 'border-width'.If an element's border color is not specified with a border property, user agents must use the value of the element's 'color' property as the computed value for the border color.In this example, the border will be a solid black line.p {color: black;background: white;border: solid;}8.5.3 Border style: 'border-top-style', 'border-right-style', 'border-bottom-style','border-left-style', and 'border-style'The border style properties specify the line style of a box's border (solid, double, dashed, etc.). The properties defined in this section refer to the <border-style> value type, which may take one of the following values:noneNo border; the computed border width is zero.hiddenSame as 'none', except in terms of border conflict resolution for table elements. dottedThe border is a series of dots.dashedThe border is a series of short line segments.solidThe border is a single line segment.doubleThe border is two solid lines. The sum of the two lines and the space between them equals the value of 'border-width'.grooveThe border looks as though it were carved into the canvas.ridgeThe opposite of 'groove': the border looks as though it were coming out of the canvas. insetThe border makes the box look as though it were embedded in the canvas.outsetThe opposite of 'inset': the border makes the box look as though it were coming out of the canvas.All borders are drawn on top of the box's background. The color of borders drawn for values of 'groove', 'ridge', 'inset', and 'outset' depends on the element's border color properties, but UAs may choose their own algorithm to calculate the actual colors used. For instance, if the 'border-color' has the value 'silver', then a UA could use a gradient of colors from white to dark gray to indicate a sloping border.'border-top-style', 'border-right-style', 'border-bottom-style', 'border-left-style'<border-style>|Value:inheritInitial:noneApplies to:all elementsInherited:noPercentages:N/AMedia:visualComputedas specifiedvalue:'border-style'<border-style>{1,4} |Value:inheritInitial:see individual propertiesApplies to:all elementsInherited:noPercentages:N/AMedia:visualComputedsee individual propertiesvalue:The 'border-style' property sets the style of the four borders. It can have from one to four values, and the values are set on the different sides as for 'border-width' above.#xy34 { border-style: solid dotted }In the above example, the horizontal borders will be 'solid' and the vertical borders will be 'dotted'.Since the initial value of the border styles is 'none', no borders will be visible unless the border style is set.8.5.4 Border shorthand properties: 'border-top', 'border-right', 'border-bottom', 'border-left', and 'border''border-top', 'border-right', 'border-bottom', 'border-left'[ <border-width> || <border-style> || <'border-top-color'> ] | Value:inheritInitial:see individual propertiesApplies to:all elementsInherited:noPercentages:N/AMedia:visualComputedsee individual propertiesvalue:This is a shorthand property for setting the width, style, and color of the top, right, bottom, and left border of a box.h1 { border-bottom: thick solid red }The above rule will set the width, style, and color of the border below the H1 element. Omitted values are set to their initial values. Since the following rule does not specify a border color, the border will have the color specified by the 'color' property: H1 { border-bottom: thick solid }'border'[ <border-width> || <border-style> || <'border-top-color'> ] | Value:inheritInitial:see individual propertiesApplies to:all elementsInherited:noPercentages:N/AMedia:visualComputedsee individual propertiesvalue:The 'border' property is a shorthand property for setting the same width, color, and style for all four borders of a box. Unlike the shorthand 'margin' and 'padding' properties, the 'border' property cannot set different values on the four borders. To do so, one or more of the other border properties must be used.For example, the first rule below is equivalent to the set of four rules shown after it: p { border: solid red }p {border-top: solid red;border-right: solid red;border-bottom: solid red;border-left: solid red}Since, to some extent, the properties have overlapping functionality, the order in which the rules are specified is important.Consider this example:blockquote {border: solid red;border-left: double;color: black;}In the above example, the color of the left border is black, while the other borders are red. This is due to 'border-left' setting the width, style, and color. Since the color value is not given by the 'border-left' property, it will be taken from the 'color' property. The fact that the 'color' property is set after the 'border-left' property is not relevant.8.6 The box model for inline elements in bidirectional contextFor each line box, UAs must take the inline boxes generated for each element and render the margins, borders and padding in visual order (not logical order).When the element's 'direction' property is 'ltr', the left-most generated box of the first line box in which the element appears has the left margin, left border and left padding, and the right-most generated box of the last line box in which the element appears has the right padding, right border and right margin.When the element's 'direction' property is 'rtl', the right-most generated box of the first line box in which the element appears has the right padding, right border and right margin, andthe left-most generated box of the last line box in which the element appears has the left margin, left border and left padding.。