CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。; @4 M/ Y. b1 ]+ u z6 u6 d
以下各特效用的HTML代码相同:
4 ]' Y- P8 n; ^& ~<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
0 d" r* d' S# |" y( W1. CSS动画边框
2 f+ z% q4 A( _2 {CSS代码:
( o( L# {& M# P% r" y7 v/ t- S@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;
} 效果如下:# n8 q- w h8 H# W+ b% S9 `
5 o; o' c- X- ^" Q6 V* t0 p8 p# U
1 @/ U. x2 s0 C! e2. CSS图像边框
5 i( m. u8 {6 U6 E) w/ B- bCSS代码:
% k @7 K$ k* R" t#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;
} 效果如下:& y/ P, G, R( Q) u1 N9 ~4 x
. H( ]) e! B, k2 R0 x- B3 _7 f# ^: Q- I/ J0 W6 J0 H
3.CSS蛇式边框( B9 ?, f$ k/ ]! Z6 x. t
CSS代码:
7 t3 c1 G8 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;
} 效果如下:- @) [+ k* E% x5 Q
/ H N( k. H0 J3 o; L# |
/ U# o) B9 v+ J! P: E4.CSS阶梯样式边框
+ i' }9 Q4 \: ~$ |CSS代码:
* o. Q( d! r8 b1 G! _+ I#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
} 效果如下:; k0 a( g; v5 Y
" C- {# x4 e) ^* K
1 _& [) g2 @# l7 m6 d4 ^5.CSS只有阴影边框4 V: ]: v! \: P5 O. e, }9 C5 s
CSS代码:
. d& {/ p0 H V+ }+ m; }: Q9 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;
} 效果如下:
2 V* x2 a& u% { } O! T
3 w! W/ e1 r: \6 l0 ~" ?9 W8 b$ A2 b
^% P! J1 s: u) J6.CSS带阴影和轮廓的边框5 r+ a- f4 T2 E9 k
CSS代码:' g. L( C+ Q1 D; k& b& I! B: P
#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;
} 效果如下:
+ N, \6 r4 u/ K3 |
7 F# O) E0 ?' s- ^
- y$ D' D y: h# H# u; L3 a7.CSS少量阴影和轮廓的边框
2 x& x0 _; X$ Z4 ]" ~CSS代码:' h# S; i }2 F r
#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;
} 效果如下:
4 h; U. V, x; ?8 b) U ^
' L B) D4 C# [' C
* p3 U" x0 v% V# X% v( z! ?
8.CSS带有阴影的双边框+ O: C5 `. x1 u# N; b7 x
CSS代码:
! X/ k5 U' h! c" i* F#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;
} 效果如下:: ~5 `8 ^5 [/ x, y7 j
/ @( f8 g/ Y2 Q
$ o3 E" D; u6 g6 X; A) [/ N
9.CSS多色边框
9 M1 P/ D7 S6 VCSS代码:" ~( K5 m ^: X' `& O. V
#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;
} 效果如下:
5 I$ g! y. S8 E& v: w2 C
|