CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
! q1 Y+ W; M% D6 j( F 以下各特效用的HTML代码相同:7 {4 b x U. R5 D4 e8 k! E
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
/ y) v( M. b2 a! q+ Z1. CSS动画边框
/ Q: ?# b+ j, qCSS代码:
' Q4 ~4 K8 u' U" k; s7 G@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;
} 效果如下:
5 V0 V% n/ b. t, M
* J$ t1 P! D+ D m4 f- f, J5 z) y5 u, G# y" u4 F
2. CSS图像边框; K7 ~5 Z. J. G" D$ z2 @
CSS代码:" s2 p9 m1 E% g+ f4 V- ~
#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;
} 效果如下:
8 R5 q+ K5 t" }' c' M
+ C0 Y* u9 d! I2 b/ h8 y: p# C/ {4 l, H% u5 j: V/ N
3.CSS蛇式边框' D0 A- h/ b) y6 o: D4 V* ]9 W# B
CSS代码: G$ N8 ` C# _0 m0 S% u t. g
#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;
} 效果如下: _" h8 D; ~+ z( D5 o3 }
0 v) s# I# i6 n- j8 m
6 b# C, |2 W3 f) Q! f4 s( g7 w4.CSS阶梯样式边框+ ^' q4 P# g2 w7 |$ x
CSS代码:
4 u( [! a s9 g5 T1 w) \- `; O( f, W) M#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
} 效果如下:* g+ l& {& G6 F3 V6 `. A
0 x8 F) U( |+ v- x( V: ]9 i+ G% S5 }, _# j/ f% e, t3 w
5.CSS只有阴影边框
# }6 m$ t1 j8 J) E$ CCSS代码:% h" ~9 F( w( u$ I
#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 R0 J" k) J9 W' z( }
[+ @* [. ]' O- {) p# ^( M' K0 R- p p8 P& ^) C$ }% @
6.CSS带阴影和轮廓的边框8 x1 n4 C" m* |( f( u
CSS代码:
- I7 A" S: X$ x) F$ T$ W$ ~) 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;
} 效果如下:
! {- I" y; x7 i" B/ U" f
k% L/ v' h2 e
+ i. o* L5 L3 u4 x2 j& B
7.CSS少量阴影和轮廓的边框( u% r! O! U6 D4 p: g
CSS代码:
/ f; ~% P8 J ^#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;
} 效果如下:
7 f a! i( |9 H6 W* {7 O
# U8 r- ~2 m( |
5 j! ]/ _/ A& p0 y8.CSS带有阴影的双边框
- l7 \& m3 l+ [; nCSS代码:
/ d' M. R2 y e# a! A5 c X0 `#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;
} 效果如下:2 ]6 K4 ~7 W0 I; ]' k% t
; O- ]9 d; Y$ @/ T. P' a* \
) B5 f" F- H5 }/ h, g& I: L- F4 ^9.CSS多色边框5 n" x$ ]3 n- ^/ w8 }5 n' ?! W( c
CSS代码:
, s8 ~& k2 T( h+ p- M#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;
} 效果如下:
1 x* I3 X# c' c
|