CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。8 z% S0 o9 Y. G5 `
以下各特效用的HTML代码相同:
1 \9 [5 D9 ^" R3 E; a9 n; ?<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 7 |3 _7 v9 h% D: ?2 g
1. CSS动画边框
- Z2 c6 D! K' d- {; wCSS代码:
; I2 ~* `0 k' c7 Z@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;
} 效果如下:
- a7 z9 g8 ^2 R: W2 i3 \: V, E
5 l# r1 N+ `$ V3 g* {. U
6 Y E7 N) R! p' G b* }, P2. CSS图像边框) s/ a, V8 ]0 s; l. k
CSS代码:
9 W$ s# N7 F/ I! X" f& 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;
} 效果如下:7 ~, Y3 ^9 i @. r' {& i- T0 S+ U R
) [. a0 }( Z& W' @
$ _8 T/ Q, Q. C1 R3.CSS蛇式边框
9 b/ ]$ f i6 n3 v' CCSS代码:
3 W$ ^0 @6 C/ c#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;
} 效果如下:7 |3 B3 t( f Q0 j% N
& z( M. U2 n; ], T
- n( T/ T" e9 d1 U( H4.CSS阶梯样式边框
. q$ r! W5 {3 T* o9 S4 ECSS代码:9 F3 w* U- a+ W. N; F P
#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
} 效果如下:
9 C, v. E8 j( q' `: k2 K0 c
6 F( Z+ l3 X5 |& f1 t A5 }* ~, j$ n' Y
5.CSS只有阴影边框
1 u2 f3 Y: `' LCSS代码:
; d- Y, H' q3 E2 M6 G#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
. Q( u8 c* \$ l( ]. I/ O. C, `6 }: m3 n
5 A4 K5 Y9 ]& f n/ K7 d! B6 i2 m
/ F5 _7 H. n7 u7 d6.CSS带阴影和轮廓的边框
4 m" U+ \8 r6 s( R9 LCSS代码:
w) w# \, ^" g. |: B) ?#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;
} 效果如下:
1 F6 W! {3 H* z' Q, A5 h
7 T' P5 \+ ^% m# E8 c
, k# H1 d: x( |
7.CSS少量阴影和轮廓的边框) i* O$ H# F4 i; F* t) J
CSS代码:& d2 B; \# B9 t0 _& s
#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;
} 效果如下:
c K/ `5 P( B" ]" o6 K
* B2 ^* O i8 P' ]
0 R) @0 p; A- a) W- i9 e3 V! X8.CSS带有阴影的双边框 W' u1 ~ y9 p; f, f" ]3 R1 g
CSS代码: i3 M$ J$ B1 f+ w
#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;
} 效果如下:* I" m, \3 h; o) U6 {
3 W+ u. c, _* z; G4 l
% P" k5 e1 M2 m8 w9.CSS多色边框' F: A7 O3 |) g* P. J
CSS代码:$ b6 {$ o) O1 ~) e2 b
#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;
} 效果如下:
\% m/ z! O' `+ d/ O2 R
|