CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
7 c5 p, M* Q3 @$ q6 |. V% k 以下各特效用的HTML代码相同:$ r- F: c' m4 Z. F3 g' N
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
# F8 X9 {# R x4 I7 t1. CSS动画边框
% @0 i, t7 z' dCSS代码:) M: Y5 X4 J0 X: Q
@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;
} 效果如下:
" e% X6 X @# n
& y' R2 u# N3 [+ k V
. n: ^' k7 U: u! O- S
2. CSS图像边框
$ M% |" b4 m T1 x" SCSS代码:( A( \1 X7 `3 X( x+ I2 U# B
#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;
} 效果如下:$ |0 @( d7 q( H" _; _; F) l+ F
; [" t2 c7 K% L. f4 Q* r5 j2 S+ w
" H5 N2 @( ?2 H6 K& U
3.CSS蛇式边框
( [7 `2 \! J9 R! H, _+ Z2 z+ y4 |CSS代码:+ ? F! z5 N# q* 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;
} 效果如下:; L: P# {$ e" E# C" ]
! p2 T/ M/ v4 W
& D) ~& q, S$ R0 B* x& x' ?4.CSS阶梯样式边框
/ q2 U; y6 o- K# n7 b5 L5 v7 N: |CSS代码:
3 ]- X8 j* R' T, p* y#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
} 效果如下: B9 f1 S7 }) o, `* e7 l7 @6 {4 j
' X9 r9 [9 l9 m, \( _$ ?- Q/ U( Z
; g D) I" d( |5.CSS只有阴影边框
5 h0 ~4 A6 K# t4 OCSS代码:
9 ]5 }' ]' R- j9 C+ k#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
6 f: Y) r, ]7 l- x$ `
+ [0 w; Q; C# n, x
& z$ j1 ~) o; x6.CSS带阴影和轮廓的边框
& C/ F( p( T; c. X! _1 G7 NCSS代码:
6 ^* I4 D. |7 J, j' K; S#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;
} 效果如下:
' x2 p4 { n+ P5 T1 h
: N3 f2 r/ p6 t, @& |5 E m9 m/ ]' Q# j1 N! V
7.CSS少量阴影和轮廓的边框
3 R* G) p- n- F% wCSS代码:
9 V" R% S9 ]3 e1 Q: A#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;
} 效果如下:
& u+ P; `) N) ^$ h3 l
/ a0 S8 P; y9 J5 Q+ W9 b% u
5 }: p4 k$ M; e8.CSS带有阴影的双边框
5 J- g" J( d! }, `0 KCSS代码:
: P' w; t4 P5 F8 g! ?7 D% V#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;
} 效果如下:9 y1 R- [5 j1 Y) u) Z
& [* e( ^( |# Z6 s* Z) ~% B( @
& }+ Y$ G: x' G7 b
9.CSS多色边框
0 x/ Q3 L2 I7 eCSS代码:
1 c- z5 l6 N& w#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;
} 效果如下:- o( Z# ?, b7 d+ X2 Z; F
|