一.CSS 盒模型
margin:没有背景颜色,是完全透明的。
border:颜色受box背景颜色影响。
padding:颜色受box背景颜色影响。
content:box的内容。
元素的高度和宽度
设置高度和宽度时设置的是内容的高度和宽度。整个box的高度宽度由以下公式计算而得:
总宽度:
Total element width = width + left padding+ right padding + left border + right border + left margin + right margin
总高度:
Total element height = height + top padding+ bottom padding + top border + bottom border + top margin + bottom margin
二. CSS 边框
1.border-style
border-style可以具体到border-left-style,border-right-style,border-top-style,border-bottom-style。
border-style属性可以有四个值。例如:
(1)border-style:dotted solid double dashed;
top border:dotted
right border:solid
bottom border:double
left border:dashed
(2)border-style:dotted solid double;
top border:dotted
right and left borders:solid
bottom border:double
(3)border-style:dotted solid;
top and bottom borders:dotted
right and left borders:solid
(4)border-style:dotted;
all four borders:dotted
一个例子:
<html>
<head>
<style>
p.none {border-style:none;}
p.dotted {border-style:dotted;}
p.dashed {border-style:dashed;}
p.solid {border-style:solid;}
p.double {border-style:double;}
p.groove {border-style:groove;}
p.ridge {border-style:ridge;}
p.inset {border-style:inset;}
p.outset {border-style:outset;}
p.hidden {border-style:hidden;}
</style>
</head>
<body>
<p class="none">border-style:none</p>
<p class="dotted">border-style:dotted</p>
<p class="dashed">border-style:dashed</p>
<p class="solid">border-style:solid</p>
<p class="double">border-style:double</p>
<p class="groove">border-style:groove</p>
<p class="ridge">border-style:ridge</p>
<p class="inset">border-style:inset</p>
<p class="outset">border-style:outset</p>
<p class="hidden">border-style:hidden</p>
</body>
</html>
以上代码运行结果:
2.border-width(边框宽度)
边框宽度的取值可以用pixels设置,或者取三个预设值中的一个:thin,medium,thick。其中,medium为默认值。
border-width可以具体到border-left-width,border-right-width,border-top-width,border-bottom-width。
Border-width属性可以有四个值。例如:
(1)border-width:thin medium thick 10px;
top border:thin
right border:medium
bottom border:thick
left border:10px
(2)border-width:thin medium thick;
top border:thin
right and left borders:medium
bottom border:thick
(3)border-width:thin medium;
top and bottom borders:thin
right and left borders:medium
(4)border-width:thin;
all four borders:thin
3.border-color(边框颜色)
颜色可以用名字,RGB值或者HEX值设置。
border-color可以具体到border-left-color,border-right-color,border-top-color,border-bottom-color。
Border-color属性可以有四个值。例如:
(1)border-color:red green blue pink;
top border:red
right border:green
bottom border:blue
left border:pink
(2)border-color:red green blue;
top border:red
right and left borders:green
bottom border:blue
(3)border-color:red green;
top and bottom borders:red
right and left borders:green
(4)border-color:red;
all four borders:red
4.border-shorthand property(边框简化属性设置)
将三个属性放到一个属性中,三个属性的排列顺序如下:
border-width
border-style (required)
border-color
例如:border:5px solid red;
三. CSS outline
outline是在border外面围绕元素的一条线。
outline不会影响元素的总宽度和长度。
Outline元素可以有三个属性:
outline-color
outline-style
outline-width
四. CSS margin
margin可以具体到margin-left,margin-right,margin-top,margin-bottom。
margin- Shorthand property
marginr属性可以有四个值。例如:
(1)margin:25px 50px 75px 100px;
top margin:25px
right margin:50px
bottom margin:75px
left margin:100px
(2)margin:25px 50px 75px;
top margin:25px
right and left margins:50px
bottom margin:75px
(3)margin:25px 50px;
top and bottom margins:25px
right and left margins:50px
(4)margin:25px;
all four margins:25px