CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。- }( @* k, R5 F
以下各特效用的HTML代码相同:
& c" N% u" z9 y9 {. T<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 7 d0 E- n" P3 h0 s
1. CSS动画边框2 {. n) q5 t' h& R' R# _3 m
CSS代码:
# B5 m7 R! Q `- A+ `' x@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;
} 效果如下: V- r: I- V8 T) m2 D
0 ]" z5 T; `. A. }8 G8 n: z7 Y
) I6 z9 G; d$ e# A! k4 v; Y2. CSS图像边框
* q0 \4 _4 I# t& `+ W5 Z8 @$ r3 r: f9 VCSS代码:
, d% L9 F1 G! t% H! Q# H# z9 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;
} 效果如下:
e+ ^6 s4 P& v) D; x6 Q. ]
& L* }, Q7 w. u
6 y8 h" ~5 c0 t) \8 D' c3.CSS蛇式边框# H8 f: O5 ~, J; {
CSS代码:
, D5 L# E2 x3 x) i$ E#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;
} 效果如下:
, w% H- Q' v f5 {7 p- G+ M4 [
' S1 E, S" _) B. P
& T% v6 E# C" \) K7 z* Y5 c% r4.CSS阶梯样式边框
, x: O0 M/ |8 G; x( qCSS代码:
m+ P, V# z3 A8 A" A#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
} 效果如下:
6 `$ n l) w- C" k: a! D3 L
: U2 T# }: m1 o! b _) y- X7 E4 l* u; L2 X( W
5.CSS只有阴影边框
- Z% I$ ]1 x6 z' L U, g6 tCSS代码:" ~& |3 j( e0 M* N* Z3 h
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:* l7 ?$ k; c; d6 \
$ ]7 _" L6 v4 \7 x; G
4 g! [: _! g: N7 l5 R3 S6.CSS带阴影和轮廓的边框9 o0 X3 k8 i8 m4 O+ N2 O
CSS代码:
; \5 j8 i4 b2 \1 C#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;
} 效果如下:
, t; F d, Z7 b- e) t
% @ k# t0 I7 @) \) h
/ @. v5 W' ~3 _; b0 m% K' z% b1 k# U
7.CSS少量阴影和轮廓的边框4 p) R7 |0 ~! [8 N
CSS代码:
% l; A8 k: A0 u X#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;
} 效果如下:' {& S) T, I0 [7 p, @! n( ]
& `* i$ V: K7 } z$ S, r& N5 b$ f8 V1 x* T; U G& {$ L
8.CSS带有阴影的双边框* d# Y) Q3 h& @) \: ^7 L- ]
CSS代码:
" r7 L5 W; _4 s; f, o' K8 I; 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;
} 效果如下:
H8 w* C: L! P' C# V
9 q1 P% {$ D/ b; h( n
) O B f2 C, p9.CSS多色边框7 H+ }. O: j$ `+ _& U2 x ~" ]
CSS代码:+ M+ ~/ j2 T' Z7 V0 H
#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 j0 k% z9 K7 O0 E, i/ `$ V
|