CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
/ a K, p P5 ^4 F 以下各特效用的HTML代码相同:
- i* L6 ~( ^9 g/ j: V# @1 |4 ~<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> - A& X* M$ }7 G/ \) @2 U
1. CSS动画边框
) B8 ?4 ]- k/ I6 Z0 [, kCSS代码:
5 ^, x5 |# B9 @4 R2 I' [0 @; D1 \. p@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;
} 效果如下:! j2 d4 A$ U3 Q5 V+ t
7 \" i1 @+ k. V- M% v, I* q: l+ O3 D1 ~4 p* C! K' I9 [
2. CSS图像边框0 k; j* q% @, b" g' |
CSS代码:" K0 I9 U: \0 I4 E. U3 a
#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 @/ m0 ^1 K
8 X( j$ ~5 n' [3 f
: B: F) z% h* h- `; o. c3.CSS蛇式边框
5 t2 M' o8 G! |1 Z# o$ CCSS代码:1 U$ C( d" s' N: A
#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;
} 效果如下:# a0 @& y' l R& u3 O
]0 x% c6 S N X- ]
$ ?/ }* p5 |" ^* T; v$ }9 f4.CSS阶梯样式边框: q! S9 s) ~8 K) i4 Z+ k
CSS代码:
% \* A9 S4 z) i" l) B! E4 d2 ?#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
} 效果如下:
! J8 w; C7 g1 `$ M* t
% I/ h/ r) H6 E$ U' B0 a2 L- N: X, s
+ i2 K+ X6 S6 M. ]2 L. H+ _% |
5.CSS只有阴影边框; ` d6 z( {+ Z
CSS代码:. p+ C9 {7 b8 W; R f8 d& A8 r
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:6 c3 e* C( o& y$ z/ W. @
" Z) ]4 F3 Y8 b5 |$ V* ~+ u1 Y2 d+ ?) \5 p/ V+ N3 c% i0 t
6.CSS带阴影和轮廓的边框! b/ B' `+ |, }3 b s
CSS代码:
( F) Q7 _" M0 {, x% U8 w2 o 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;
} 效果如下:, P4 y; S# c5 D
1 b8 C, P9 P& m- N5 q% V6 a0 U
: u0 @+ E9 g1 G* v v4 J1 g o7.CSS少量阴影和轮廓的边框- P: k. O n( r/ V) l2 n5 d
CSS代码:+ F {3 }( P3 D4 f; B" b( D$ [ z
#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;
} 效果如下:' a) y/ j+ I- p7 \% T, Q) @
2 G2 \- |& y/ k& V* t% G0 \6 z3 N
/ j! g3 S) s% E6 _8 c8.CSS带有阴影的双边框
! V- Q: ]. q+ M/ k0 k" ECSS代码:# ]0 S/ W! u. q" P X
#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; G {& O: d9 P, c
. u+ B$ l1 c" T
% z4 j4 l. h" k7 _1 w. J9.CSS多色边框
; q( F* H, d- A8 S: mCSS代码:
/ k; P3 ~6 b7 @#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;
} 效果如下:+ g" k2 i+ E! R# @' {; B5 D
|