CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。3 o: F) |: H5 `
以下各特效用的HTML代码相同:: E; V# N) V7 R/ `
- <div id="box">
- 编程适合那些有不同想法的人... <br/>
- 对于那些想要创造大事物并愿意改变世界的人们。
- </div>
4 ]' K3 a/ w6 ^
1. CSS动画边框- l& b3 j5 B* [: D' b6 z3 ^( ~
CSS代码:
& d$ k0 R8 f$ U( ]) x0 `- @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;
- }
效果如下:3 I U5 a5 N# p4 ?
8 g) R) w0 @% `. T, A; ~3 F
2 z3 H8 H4 d& ^0 N1 w% ]2. CSS图像边框
: b3 U9 k3 e h* N; e& a/ \& g; MCSS代码:
2 L$ G9 d* K+ ^4 E% O& X7 ~( t- #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;
- }
效果如下:: o8 Y/ y3 t1 v* }' v6 C3 m
: x: C$ U6 e# N& F9 M t
/ q( ?7 O2 H5 l( P
3.CSS蛇式边框' H/ P7 r& K S3 J( U$ ]2 f! W
CSS代码:5 |! \7 ^/ U7 v, J Y d. t: Y) y
- #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 x" R; b6 L% y: b! `8 n& a
( q, ?! n3 T- f8 a4 e
1 y4 s# r2 U- f4 M* ^% u4.CSS阶梯样式边框' T7 @& a# Y3 l& Z' J4 r3 A' w
CSS代码:% ]2 a: O: b/ ]! ~& _3 k* N5 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
- }
效果如下:0 _; C6 ]' O, i1 O5 _/ y6 J! D
/ w$ ?+ g& `6 V7 Y4 W" Z% I. R
0 a* }9 ]9 v1 i" j0 V3 L, [
5.CSS只有阴影边框
+ i4 P* s+ J7 r; p) x! \/ \/ W0 X% DCSS代码:
- t1 L7 q& l0 i( ^! Y- #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 L8 q5 T0 v# ~$ f+ o1 V/ P
& i' `- O# W5 H
, p( |! O; Q4 E$ R- A6.CSS带阴影和轮廓的边框
' X& m" m; I5 e" f2 }CSS代码:
. O$ u0 d) g3 P) K/ g L- #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;
- }
效果如下:' w9 x3 P, P' v' B
& Y6 o t7 B0 |! ]8 g* D/ z
) t, t$ M5 m: e7 `' V: p6 I( o7.CSS少量阴影和轮廓的边框) }3 ]8 z2 s+ ]
CSS代码:9 p' E5 z/ J' F9 F
- #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;
- }
效果如下:# U4 K8 k/ r* e, {
8 m! v/ V- C o/ ^* f
- C( A8 H) q; i1 |. K2 \7 ]8.CSS带有阴影的双边框! |5 N V, A- S& Y! Y9 r0 s8 M
CSS代码:% @6 k5 a4 _3 g$ R/ K9 D$ q
- #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;
- }
效果如下:0 M9 j5 T: S# G8 Q% r. S0 l8 d' j& F
; H5 C# n3 R0 T# C3 G0 c" s) ]
3 d; x H- T4 I( E! U" M) ~- j9.CSS多色边框
% T9 f. b- `4 c3 r# B" n8 L/ j& uCSS代码:
+ W, N' n8 [- k- #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;
- }
效果如下:3 E. A) }& t* }# Y2 {. w8 y# w" I* x; O
|