CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。* f0 G8 Z# `" @& Y b( B2 w
以下各特效用的HTML代码相同:$ v$ N- i9 u+ W f
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
* j' @$ f$ j" r8 v7 D, M) w, ~1. CSS动画边框
6 X: o5 _- v( P) \; ]CSS代码:
7 O" }2 _/ d% }8 c@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;
} 效果如下:
9 N& s- g6 X$ [- i/ {
J2 k G; \% Y2 S7 Z2 j0 o
" c% o. v3 ]1 S' N1 \0 Q, w8 b2. CSS图像边框: z5 o- u! z8 K2 O! j+ u
CSS代码:
\ k+ W, F4 y+ j#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;
} 效果如下:. e7 X( @( Q1 k( R
; R9 h5 N- P* D- `5 ~: X+ u$ N7 H8 I8 Z4 p- ~$ ?% v" R
3.CSS蛇式边框+ H" M5 M+ F# r9 m/ a( V
CSS代码:
$ e' z) L X; V2 t2 Q, c1 k#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;
} 效果如下:
7 M! P" M: c. m$ J" H$ E
- W9 d/ K& P, x9 W+ w; g7 ?, \7 @3 U: o; C6 m# |
4.CSS阶梯样式边框+ a _2 f) ?" J7 d; j' t! w
CSS代码:
( E" y+ o9 }5 q#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
} 效果如下:
! r0 x2 Y' }1 B! A
$ w- l x; Q4 U8 Q/ R# h( D+ ] e0 z# h! L5 K- }/ C; T; |3 g
5.CSS只有阴影边框
2 m# x9 y+ { y5 {/ tCSS代码:, l$ J! ^) v0 n) ]! o
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
# r: }* d) W' i. |
: w9 g1 }1 ^7 T' O
8 f3 m, e. p+ m
6.CSS带阴影和轮廓的边框+ Q9 \8 U3 `7 K3 Z& m4 s8 v& J
CSS代码:( W# k. P4 a" k% b6 Y$ B
#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;
} 效果如下:6 k! Y; ]6 b9 x" S! m L' z
) l5 V. i8 {0 L. O# h# i9 B6 Q/ h9 @' `" i0 L
7.CSS少量阴影和轮廓的边框& r$ ~ z, T- D6 ^
CSS代码:/ ]# D- v- ]4 j% z: W( t
#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;
} 效果如下:) M* X: n0 I2 Y" {& ~3 c
& G' i% i j# H
* Z+ `' s4 j6 b5 X: L2 o8.CSS带有阴影的双边框
+ u h" [- f; P7 NCSS代码:
9 R! U3 j% L. w' X, e; ~5 ]. ~#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;
} 效果如下:6 ^3 l: a4 k+ F0 k' y. O/ Q
" w! b, F3 \1 k! `8 v9 M; o
X+ v# Z. |+ p2 u9 d2 p+ o! F9.CSS多色边框
3 L0 U$ l4 J i. F& l5 `1 w: f! QCSS代码:
( Z& e% f$ o4 E9 {- r4 Q9 M& a#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;
} 效果如下:
- S z8 Z( c- @$ L6 x' Z
|