CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
- T0 {7 C+ T8 n6 x- H7 s 以下各特效用的HTML代码相同:1 g* l. U. \. {. I
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ) S( g/ ~0 J# u9 j7 G5 @4 x
1. CSS动画边框
7 _) ~ e' y+ `8 G" JCSS代码:
K0 ~9 y2 f$ D$ u/ [! M@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;
} 效果如下:/ a& |6 s# d9 V- @7 W
, ?6 d) \* B! Q2 J+ G3 Q; C& H0 M; J3 n1 o: f2 {6 a
2. CSS图像边框6 ?# q, b" p" E8 \
CSS代码:
: C/ g- }. `0 {" n' T0 M5 I#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;
} 效果如下:" Q) s+ K, L8 d2 O9 G* z5 S* N
" _7 {" I5 q. [# {
/ i6 L p3 u# K
3.CSS蛇式边框
* u5 o' \7 l$ j% M |CSS代码:4 h* w, ?/ x6 |1 N
#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;
} 效果如下:
" p4 b7 ~) u. G; M
, j5 X- j" l5 o5 G* p: W6 Q8 c
1 q1 s' X- g7 J) S4.CSS阶梯样式边框
! ~3 h0 N: F' @8 sCSS代码:- ]. \% e" ~& W+ r( k
#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
} 效果如下:; P8 _1 N3 \& V% Y
9 s! |% E7 }/ d+ y5 O* x
4 _# e# X5 b' u5.CSS只有阴影边框
( f: q, ?9 {/ O, ^CSS代码:
' i7 U: V7 v$ P5 Q3 l6 X1 u9 X#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:# b6 {! |1 P2 s% R7 U& U0 v' Q
% ]1 [# c S" ]& r. Q1 o7 Q1 D
1 P3 d0 D6 b, X0 F
6.CSS带阴影和轮廓的边框
! H$ h2 x6 K) B# HCSS代码:
8 _ P ?( b' Z- W#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;
} 效果如下:! }( W% Q& p3 L8 l6 y4 U! i
I0 P: |2 B+ k$ y) h' X
' Q# e0 b# ^& F# x7 J4 F7.CSS少量阴影和轮廓的边框" z5 k/ i' B# n. o/ M
CSS代码:! ]& k, g. D( X: P7 {
#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;
} 效果如下:
$ j# B! y- N% ^% e" ]
1 J" ]1 Z1 e# V: S6 R/ V1 G
# u9 ?3 g3 T5 J/ A! {6 B8.CSS带有阴影的双边框
1 v6 f4 |8 p: h/ \- h0 b- P7 {% PCSS代码:' i0 F1 |6 Q, A G+ |, x" G
#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;
} 效果如下:
* j+ W* Y" _! _4 V* @- d4 W/ B
" X m1 {" `0 S
J9 ~6 s b6 K9.CSS多色边框: u8 T# s9 [& e1 l! E( b/ ?/ M
CSS代码:- b0 L/ w3 k7 s5 X. T
#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 Y4 ?; O8 ?% ?2 F: Y8 v4 ^9 U
|