CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
0 ?2 I+ v! V2 E" z" |# t5 W 以下各特效用的HTML代码相同:( p: D, G& S: b1 F9 l2 \% \
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
6 p" N9 x0 \+ x7 i& V8 d8 n+ S1. CSS动画边框
& g7 A, c# ~9 @. I) ]5 B; ]CSS代码:3 S' S' P' B( n7 x
@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;
} 效果如下:
. |( F$ ^+ y: {$ ]1 s
5 c( _+ V- |8 k2 s1 g
' t# b# x9 C( f2. CSS图像边框. \; t2 M( U& B; [ E2 j8 V% W
CSS代码:
; c/ _& Y# w, e3 L. ]/ l0 \#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;
} 效果如下:
) e# O! h+ q$ K( I# f9 v- Q9 b4 c
: r2 g1 h: U+ w; D
7 g0 |: C; }/ N
3.CSS蛇式边框& b0 Y% |9 l' `$ |. O |
CSS代码:1 ^. s- H+ o% K7 m: r
#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 d. q9 f, K8 U1 K. M. ~/ T
/ S, z/ q; T7 N- {, r% s- ]
1 d' ~" {) H7 l( j" n& j" Z8 b
4.CSS阶梯样式边框5 m4 S5 I4 h, c+ T4 S
CSS代码:
2 m q- q8 }3 Z. s#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
} 效果如下:
3 s2 z% x, D: J ?
/ ~/ V$ V. @, N { x
; Z% v, E7 s v# B. T: E$ h1 E' W- {5.CSS只有阴影边框
. l1 {% r4 {8 ?: T6 v6 oCSS代码:7 I+ @0 u* |8 h% E. W1 x" l0 o
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:( s' U. X( q; R; ^% f9 i1 f" o
+ J- p5 W% s! O5 ?- Z2 R$ z* ~+ }; E$ j
6.CSS带阴影和轮廓的边框+ G- Q8 Z0 h% G6 _: {4 b
CSS代码:
0 G+ P7 _- M2 L+ d7 T( I#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;
} 效果如下:
2 H9 q+ r2 @8 m
( I8 @: q5 _! o
' x" u! N, j" ]0 v: d7.CSS少量阴影和轮廓的边框
: r& U2 j" l2 YCSS代码:
L. Y( c' w$ o% 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;
} 效果如下:
* D$ E2 e, Z" p
( C, {. x9 z1 T$ M4 j
' h9 N; r g" V4 @% b/ N- K8.CSS带有阴影的双边框
9 i/ u) a! z$ d) p: Y& eCSS代码:
, N* _4 ?9 o1 d& u3 W, ~ l- `#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 r, v5 P* U! O
! {" a( f9 d0 S X6 L ^, E6 [* t# B. h8 z8 n( B k' t9 j
9.CSS多色边框
* ?$ Q g6 K: ]. b3 y& `CSS代码:
( R8 A9 K% g! h+ F4 i. d5 _#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' x" \& ~7 z/ e2 U
|