CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 _# l1 ~) l6 p* d0 n9 |% Y
以下各特效用的HTML代码相同:
0 g! @' r q+ S<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> / y# r' d2 ?" W
1. CSS动画边框
2 u# G& r- R4 M _! i3 Z3 T7 sCSS代码:
) ^5 M5 h$ r* M# m- N" N' c; [( y@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;
} 效果如下:
* r; Q4 w7 |6 e! _! q
0 x1 l6 p; K+ Z% E# L
9 @8 r& t: M% k+ q0 m2. CSS图像边框
3 f+ o! ]9 k2 N6 w# x; Z# J0 u# {( iCSS代码:8 {/ i y) m! ^3 y3 F% r- i
#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;
} 效果如下:/ U2 w- O+ r5 e/ v3 V! U' \% I2 D
! i& H* `/ I( N) Q6 S% V
9 N! k8 y9 O6 f+ G/ q( N. A
3.CSS蛇式边框
/ c0 ?- N7 `; s5 B9 ^CSS代码:
- F h$ _+ q L* p% `0 {- v#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;
} 效果如下:- o. ~& Y& d8 @4 M1 Y. C- p& S
/ w1 t0 ?5 g" T+ f2 i. ]; W/ F
4.CSS阶梯样式边框
- h# K; r: j1 y, W& aCSS代码:
# o, ~) X) h) Q- V- s: i. I4 C#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
} 效果如下:, N- e* F) P( p2 L# O: |
) ^' }8 |* l6 A( q' a# J9 R1 g
. S: P/ ~2 K- ~* y9 ]
5.CSS只有阴影边框
0 s9 Y# I" |# c, k) CCSS代码:
' w2 S# @ [" d" K. l#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 q- h" a3 @2 a: `: ]9 Q. T
9 O8 U! [: i2 }3 D/ j
+ a- X3 d! W7 Z* Y" }3 m) ]/ J6.CSS带阴影和轮廓的边框( Q- ^5 g i, V$ [' f
CSS代码:
% u( X2 Y+ o/ }+ d' 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;
} 效果如下:
% ?9 K8 C! d$ z9 g% u
, V( Q7 T: e5 Z9 G& M
+ j- R' r2 I5 M+ i1 p9 ^7.CSS少量阴影和轮廓的边框
& p; `, s' ]% _) @CSS代码:6 E/ d m A/ e4 |5 i" Z
#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;
} 效果如下:
. Q" ]- s9 l6 [9 o
1 g2 A3 T% S0 v: _- r2 h% s
0 ~7 V* w. R3 P3 A, i! q8.CSS带有阴影的双边框+ f U- k+ W$ N( z# b: y! e. u
CSS代码:
2 Z) L6 ?1 b5 L9 m u3 S# E, m#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;
} 效果如下:
" u7 \% a8 C! I) s
8 o9 x" U/ b# b+ g; L! g- A) w3 ~3 y2 {5 h( @- [/ m
9.CSS多色边框
8 r; b x, O. PCSS代码:1 H! N9 Y; h% M) V- O9 _
#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 p+ v" P3 ^4 p" v1 {. d
|