CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
$ q& b; j3 [7 j n 以下各特效用的HTML代码相同:' N) U; _% J: O5 a4 w+ |
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 5 W' V9 ^) H3 X( ` U
1. CSS动画边框( d. C1 j+ i6 S
CSS代码:
" z; Z5 n" N+ Y+ [- l" j* T@keyframes animated-border {
0% {
box-shadow: 0000rgba(255,255,255,0.4);
}
100% {
box-shadow: 00020pxrgba(255,255,255,0);
}
}
#box {
animation: animated-border 1.5s infinite;
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
border: 2px solid;
border-radius: 10px;
padding: 15px;
} 效果如下:
6 v4 b# K+ P/ Q/ X9 O& j9 p/ ?+ _
" F6 M' @, S0 T& `. q U p
3 b* I2 A l# ]2. CSS图像边框
: j0 o; N1 f- Z3 {4 B: BCSS代码:
9 a9 \7 q, y% Y. o2 P% b- C#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
border: 40px solid transparent;
border-image: url(https://image.flaticon.com/icons/svg/648/648787.svg);
border-image-slice: 100%;
border-image-width: 60px;
padding: 15px;
} 效果如下:4 e& T/ b8 E% X
) e5 f4 ?) U1 X! G; K1 F
9 v7 `$ H; I6 E! X1 C5 s' ]% K3.CSS蛇式边框# Y z& J' K7 c; k* i# b" P
CSS代码:
6 p, ?. S$ L; ]& _- A7 W4 A% L#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 15px;
border: 10px dashed #FF5722;
background:
linear-gradient(to top, green, 10px, transparent 10px),
linear-gradient(to right, green, 10px, transparent 10px),
linear-gradient(to bottom, green, 10px, transparent 10px),
linear-gradient(to left, green, 10px, transparent 10px);
background-origin: border-box;
} 效果如下:& ~4 I8 Z J+ `1 y8 [ ?+ @
. M" {7 a+ K1 u
* }! p+ p5 h6 e, D+ @5 [! @2 w
4.CSS阶梯样式边框, T- D* m' _" C
CSS代码:
- O6 h- q7 L6 I- X( C2 {# H#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
box-shadow:
inset #0096880005px,
inset #059c8e0001px,
inset #0cab9c00010px,
inset #1fbdae00011px,
inset #8ce9ff00016px,
inset #48e4d600017px,
inset #e5f9f700021px,
inset #bfecf700022px
} 效果如下:
& I3 C: k( {% w' c3 O! ?4 N9 p
7 j h# ?8 a- j7 Z- S# a- c% B" }0 D$ J5 _
5.CSS只有阴影边框
% X: }2 [. f: r7 t$ dCSS代码:8 n# J# k5 h! Z) {/ h
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
. q5 d* S0 \+ q7 Z$ L, f
$ _1 B3 o& k+ Q# v) \7 Z5 c9 Y
6 c5 _2 I8 I+ L( l1 O# V6.CSS带阴影和轮廓的边框& i4 }; ]4 |% }6 m
CSS代码:
t* p* A* x! H% ~! q Q#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
box-shadow: 00010px white;
outline: dashed 10px#009688;
} 效果如下:7 H8 v9 E! h& o' p$ F. P
9 L8 S* X# \# ^! z. A
/ t' J3 L! @# Y( z8 T7.CSS少量阴影和轮廓的边框
+ O& N8 E9 M) }: B/ [5 t5 z! CCSS代码:
' c5 c6 A8 E& ?, r( }5 V#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
box-shadow:
0001px#009688,
0005px#F44336,
0009px#673AB7,
00010px#009688;
outline: dashed 10px#009688;
} 效果如下:
0 w$ x/ _5 }: Q; E; {/ a/ `
+ J( x0 M4 E& ]
/ t) }6 M. z/ \$ k9 P8.CSS带有阴影的双边框- `7 k3 T, Q' A2 p, ~5 Y
CSS代码:7 s8 J7 A# B$ J1 A; s8 F1 c
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
box-shadow: 00010px#009688;
border: 10px solid #009688;
outline: dashed 10px white;
} 效果如下:
7 E( P6 r4 P, d4 u' o d' G
8 l, j- U& u- m( S. K; D; p
( \. X3 Q5 I% }9 Z1 I6 V1 D9 n9 |
9.CSS多色边框
8 U: I6 O1 a- i( bCSS代码:
6 V8 m# b: J' Z O0 @9 `( t. u#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
background:
linear-gradient(to top, #4caf50, #4caf50 10px, transparent 10px),
linear-gradient(to right, #c1ef8c, #c1ef8c 10px, transparent 10px),
linear-gradient(to bottom, #8bc34a, #8bc34a 10px, transparent 10px),
linear-gradient(to left, #009688, #00968810px, transparent 10px);
background-origin: border-box;
} 效果如下:* l& e" h" f( O9 T9 L8 U% p
|