CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。$ e, E2 e) i! H% q+ ?( r& R- d# |3 N
以下各特效用的HTML代码相同:
4 U% C3 W8 q0 U<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
, o% w! a n2 Q1. CSS动画边框5 T" @% ]7 J! G D, L" L# V
CSS代码:
7 @0 K* i: J3 b9 ~@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;
} 效果如下:
% |8 p- q2 y7 N
9 Z1 h' |. N8 c# K' w" y! _* b( c: w$ ~1 k b
2. CSS图像边框
# f6 d7 J" H. D9 g& c0 GCSS代码:/ P# K G) y* W3 g: G
#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;
} 效果如下:
: W/ L; F5 J0 c+ L: w& _* Q
9 d' z, y. f) K
* m% v3 k$ [6 m9 \3.CSS蛇式边框
2 p9 \ c$ F: C8 g; |CSS代码:2 C! s7 a9 @9 A7 y! D) |
#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;
} 效果如下:
+ |4 D$ `3 K/ G9 P& {
7 {" n9 i. Y( V: b
1 _$ z2 g3 n9 w( C' V4.CSS阶梯样式边框
' y3 H$ |, M! H, T& t3 t. aCSS代码:* \7 [/ E! ^$ i! h
#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
} 效果如下:+ O6 F7 M$ t* _6 k+ @8 h( l& ?
6 D/ n5 y: |# Q/ g1 [. Y1 w2 l3 L- ^
% n8 S6 C& ` Z4 Y0 d5.CSS只有阴影边框
2 i& ]. c& |& [* P) B/ y7 xCSS代码:# r7 y2 U; @5 {7 M
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:* h! Q U% [4 S1 N* ~6 I& ^' x
4 v u1 @1 R4 U$ D+ u& n
* x. v. v0 f8 H& f6.CSS带阴影和轮廓的边框, b6 ^: ~7 l$ p- M* T+ s
CSS代码:
/ m8 W" X" i( I, f" D#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;
} 效果如下:8 w8 f* \% Y7 u0 {+ A1 L p6 W( @
2 p- ], \% j4 U" a9 x9 b% g, s
& Q! D1 f+ C ~; G# ]7.CSS少量阴影和轮廓的边框
# L; v4 m. P( N! K8 b7 g9 f) P2 DCSS代码:5 u9 `# A* j4 n
#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;
} 效果如下:& v$ m% t; J0 V0 s$ B
4 D6 v) R: S) n+ f/ O' @/ F
4 ]3 }% ~* O( a3 v5 V. r8.CSS带有阴影的双边框
9 Y5 W2 h. T0 x) KCSS代码:
1 ?. c" {9 U/ O2 {7 K* P- r#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;
} 效果如下:
" K$ b' b) d+ y6 g! H# D
, z0 h" v" v* {2 B3 R
/ K2 B& R) d: w: b2 _
9.CSS多色边框& f( U# c' N1 Z" a5 d2 Y j% Z
CSS代码:' E& a% f1 J K; I0 }
#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;
} 效果如下:, ^- R( b" m1 u# ~. b- h: v
|