CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
% j" o. @* K* P# w, W# Z 以下各特效用的HTML代码相同:* `8 F8 j" p) |6 ^* l& \9 H. S" F
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> . |' w: a5 l+ Z7 q
1. CSS动画边框% O' a& S4 y2 B3 @
CSS代码:. i8 l3 n9 B( D* ~/ r
@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;
} 效果如下:
( N% ?* c- A: }+ t7 L5 _( a- M% O
; Y, X" s3 B! f3 H3 w
* l7 `, E4 x$ w2 i: W' h" R2. CSS图像边框
8 w, I h7 I9 E6 k" `" uCSS代码:8 E- r/ e( j0 o- `7 m/ y5 r
#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;
} 效果如下:
# q0 g* T- o9 j
+ d8 ?2 c; R4 m+ \% _9 b
/ E" H5 Q+ e, h4 _. ^+ R6 e M
3.CSS蛇式边框
3 l; F) S+ J, V' ?% E4 YCSS代码:9 O& `4 D9 O V8 d5 w5 ~2 \
#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;
} 效果如下:
+ a% r; Q7 N) i' ?. I
! ^ z& x6 t5 ~3 y1 S) K) J6 h( k
; [& I: P+ n9 ^3 d2 s1 @( I
4.CSS阶梯样式边框7 x! B' ~5 o' h: j5 w0 [( c
CSS代码:3 Y4 t. L- U5 ~2 ?' }" r5 f
#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
} 效果如下:
/ K+ E) j$ y: e
! y- c' J, m- @! N4 q
( D9 K& S( Q9 ]; [5.CSS只有阴影边框
, ~8 a: @* o7 T4 P7 LCSS代码:6 l" `$ s. J3 D- c% Z, 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;
} 效果如下:7 E8 @; ?8 G9 s( _: O; P3 B' l8 C
# x& k4 N+ s7 [: w
4 c0 e9 s2 B0 n1 ^6.CSS带阴影和轮廓的边框. j0 ]6 e5 N9 \
CSS代码:
7 z/ A. M) B/ O( W% F' A( k: 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;
} 效果如下:
5 Q8 {/ l4 A5 g# I! k: l9 a
4 U- ?) R' n3 G: f! ~" y# i1 ^. k: h# v9 b; x; S! S+ [3 X. `
7.CSS少量阴影和轮廓的边框" S g/ T1 A4 P- O! z
CSS代码:
, k2 ^8 X: `* m#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;
} 效果如下:# e! _# G, @. ?$ T, E
- K# o) b4 C/ p" D2 ~& a. C9 R% ~9 a2 b$ {" f- _! A; l% x D
8.CSS带有阴影的双边框
; O" o0 Q3 q6 G# eCSS代码:( G. |" q M8 {4 f7 A/ o( 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;
} 效果如下:# t7 i) K- R$ N
( l. L# s7 S& R8 N
( o- u# A& y5 O1 P* x5 L6 W9.CSS多色边框
- k+ R9 a! I4 n9 X$ OCSS代码:
1 O% X* L% X0 s# d* r#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;
} 效果如下:
: ~$ G$ H% O% a
|