CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
( x8 X3 P' d( G 以下各特效用的HTML代码相同:1 g2 l/ k2 i- `! }5 F$ {! A
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
3 a7 F4 l; q9 ^2 y0 K) h1. CSS动画边框
9 M: r$ u( \6 l, ?5 ]2 }CSS代码:3 b. Y. g- @ 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;
} 效果如下:
% O* D, i- O1 M1 R! k: P
6 y C6 J, C9 m. I/ |1 ^9 Z$ J: B7 k& G3 w
2. CSS图像边框2 E8 x2 Z, I, Y3 E+ h$ ^9 q
CSS代码:0 l2 ~# m; j5 K- [6 y }% E
#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;
} 效果如下:
; c/ f3 y! Y D2 Y
6 F, U9 h P' g5 `" l! t
- }: r# W% O: ?3.CSS蛇式边框
) z4 i# t X- D1 x" M( kCSS代码:0 u8 D; R/ H3 k- R' Y% n# z
#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;
} 效果如下:
; Q6 p7 Q( G( `
: y% N" W2 T8 o
+ _+ ?+ _7 o! W5 U' |
4.CSS阶梯样式边框
6 I. f; K8 a2 f) tCSS代码:" p( g9 I3 j. ~% g3 B, d) {2 Y
#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
} 效果如下:
# @# ?2 o! O4 u4 q4 T; d5 |/ U
) H! b. L9 ^) T, Q
/ P% I9 @* _3 N) f- O) {: [4 m; Y5.CSS只有阴影边框
2 H% b Q6 i- I1 eCSS代码:3 D1 Z1 c1 e- A& o1 A- Q. K
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:( I, Z; a2 j7 v5 x8 w* b
1 K5 D1 r6 A4 i" o
6 u% k( D6 w, z) B6.CSS带阴影和轮廓的边框
4 Z4 d7 D5 ]# s8 N* rCSS代码:6 g" x3 B( E" 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;
} 效果如下:
9 P# ?( Q+ P6 F
( E7 _, P: o4 h- e, B5 l
! K, p; c. b2 {: F' b7 b; \( N7.CSS少量阴影和轮廓的边框
# R( B% A9 c' W2 P$ sCSS代码:/ L: J+ m' a/ F" r/ f2 I" W
#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;
} 效果如下:
( }; T+ [) l& f# R& ?5 G
% n w# U9 L% d& F9 P$ O& n
6 G2 g7 {2 f$ C. S6 a8.CSS带有阴影的双边框
- u3 |1 X" Z" s, D( @& XCSS代码:
8 S) |0 q7 U' ^5 H#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;
} 效果如下:
9 I- K- q N4 ~. v0 l, L
+ S2 o- V" A: \" N2 n/ f6 |' i5 r2 f5 N/ ?* ]
9.CSS多色边框
8 H5 @5 Z2 {1 K/ B( `CSS代码:8 Y& l' D- G! J0 ^+ ?) y8 j
#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;
} 效果如下:0 d W5 f5 |" U) n, s, p
|