提到边框,大家首先想到的是CSS的boder
属性。不错,border
属性是CSS种盒模型基础属性之一。在CSS3中,关于边框的运用会有什么样的不同之处呢?又将如何使用?本章我们带着这些问题开始我们的CSS3边框之旅。
3.1 CSS3边框简介
border
属性在CSS1中就已经定义了,使用它可以设置元素的边框风格。
3.1.1 边框的基本属性
CSS1和CSS2中的边框属性确实很简单,其主要包括三个类型值。
border-width
:设置元素边框的粗细。border-color
:设置元素边框的颜色。border-style
:设置元素边框的类型。
在实际中可以将上面三个属性合并在一起,其缩写语法如下:
border: border-width border-style border-color;
缩写后的每个属性之间使用空格隔开,而且它们之间没有先后顺序,可这里三个值中唯一需要的值是“border-style
”。
3.1.2 边框的类型
| 属性值 | 功能描述 | 示例代码 | |---|---|---| | none
| 定义无边框 | .ele{border:none;}
| |hidden
| 与"none
"相同,不过应用于表时除外,对于表,hidden
用于解决边框冲突 | .ele{border:hidden;}
| | dotted
| 定义点状边框 | .ele{border: 3px dotted red;}
| | dashed
| 定义虚线边框 | .ele{border: 3px dashed red;}
| | solid
| 定义实线边框 | .ele{border: 3px solid red;}
| | double
| 定义双线。双线的宽度等于border-width
的值 | .ele{border: 3px double red;}
| | groove
| 定义3D凹槽边框,其效果取决于border-color
的值 | .ele{border: 3px groove red;}
| | ridge
| 定义3D垄状边框,其效果取决于border-color
的值 | .ele{border: 3px ridge red;}
| | inset
| 定义3Dinset
边框,其效果取决于border-color
的值 | .ele{border: 3px inset red;}
| | outset
| 定义3Doutset
边框,其效果取决于border-color
的值 | .ele{border: 3px outset red;}
| | inherit
| 规定应该从父元素继承边框样式。部分浏览器不支持这个属性值 | .ele{border: 3px inherit red;}
|
chrome
360安全浏览器急速模式
360安全浏览器兼容模式
firefox
IE11
IE10
IE9
IE8
IE7
上面IE78910均未使用原生IE测试,而是使用了IE11自带的IE78910进行的测试。
*:first-child {
margin-top: 0 !important;
}
body>*:last-child {
margin-bottom: 0 !important;
}
/* BLOCKS
=============================================================================*/
p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}
/* HEADERS
=============================================================================*/
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}
h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}
h1 {
font-size: 28px;
color: #000;
}
h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 16px;
}
h5 {
font-size: 14px;
}
h6 {
color: #777;
font-size: 14px;
}
body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}
a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}
h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}
/* LINKS
=============================================================================*/
a {
color: #4183C4;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* LISTS
=============================================================================*/
ul, ol {
padding-left: 30px;
}
ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}
ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}
dl {
padding: 0;
}
dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}
dl dt:first-child {
padding: 0;
}
dl dt>:first-child {
margin-top: 0px;
}
dl dt>:last-child {
margin-bottom: 0px;
}
dl dd {
margin: 0 0 15px;
padding: 0 15px;
}
dl dd>:first-child {
margin-top: 0px;
}
dl dd>:last-child {
margin-bottom: 0px;
}
/* CODE
=============================================================================*/
pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}
code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}
pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}
pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}
pre code, pre tt {
background-color: transparent;
border: none;
}
kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}
/* QUOTES
=============================================================================*/
blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}
blockquote>:first-child {
margin-top: 0px;
}
blockquote>:last-child {
margin-bottom: 0px;
}
/* HORIZONTAL RULES
=============================================================================*/
hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}
/* TABLES
=============================================================================*/
table th {
font-weight: bold;
}
table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}
table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}
table tr:nth-child(2n) {
background-color: #f8f8f8;
}
/* IMAGES
=============================================================================*/
img {
max-width: 100%
}
-->