CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
i( K' l e) e3 b& U 以下各特效用的HTML代码相同:+ Y1 B5 j* B% d: T! c4 J3 U
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
6 f# x: w3 W8 G& f! d1 R1. CSS动画边框* L$ E. F+ G* e3 V7 @9 B
CSS代码:( G# p3 f8 g/ a1 p1 N; }; |
@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;
} 效果如下:2 a' R' e1 d5 F0 t) d! A2 j0 K
3 W4 h* y$ B5 b! b
: E, J3 c& t( j7 D4 I2. CSS图像边框* L Z# d2 e4 P2 U% A% M# @, R
CSS代码:4 D( m' Z3 ^3 A$ E: M
#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;
} 效果如下:
% Q Z4 P) E1 Z4 v) ^- }& v
/ t+ ?6 a+ g' K$ o& m/ J2 j
: W3 Q5 u5 J) t' }3.CSS蛇式边框9 ]8 l) _/ @2 A/ Z2 t& c$ H
CSS代码:" I% d. r& t' C0 R( k' P$ Z
#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;
} 效果如下:1 d% K- v2 m2 \. m5 l
( P1 \/ W" M& n0 t& q1 ]
$ \' a) [0 [0 {4 D4.CSS阶梯样式边框0 }) P7 s) ^: t; z. \* F+ _
CSS代码:
; r+ W' h2 N8 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
} 效果如下:. L' C, q2 f# g9 }4 z$ _
& y8 o& O( X O& g# g7 S
/ i# h( i, W0 p7 |* v5.CSS只有阴影边框
3 j1 f1 Z, X' ? b5 H: p5 pCSS代码:
t/ j2 E" l3 w* l/ p+ x#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
' W: ?# _- J; T8 N& w
1 p* s: b$ D' R' f/ d: X5 c$ G9 Q6 E
6.CSS带阴影和轮廓的边框
+ P. K% U) p# K! d* s" mCSS代码:) w- C. f( j( a+ R9 p' {( y
#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;
} 效果如下:& X/ S2 Q( T/ ?0 }. a+ q
3 D4 B G& @; m$ h7 m' k( @' c
% Z* S( w5 ] E7.CSS少量阴影和轮廓的边框" E9 T! W% t4 M8 E! y
CSS代码:( ~* ?5 m4 y i/ b( t
#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;
} 效果如下: T+ g9 K4 h, i' B* N
+ ^% u4 K; s* F! ]* ]1 W
. v* x7 d4 U& G$ |8.CSS带有阴影的双边框
) T0 E! X# ?# n4 e* l- mCSS代码:
; b) o' U2 E6 s* N#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 q. K! C9 v8 O; q; F; P. X. M
% S% I# [1 Z: N; ~3 G c/ P8 y/ T" H5 S
9.CSS多色边框
5 T: V# I/ u d% m5 L( s; ?CSS代码:
; Q) |. j2 m" V7 i, A1 B9 \#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;
} 效果如下:
0 B8 i2 y2 m( I# V
|