CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
, j- o7 R1 U# s9 @/ b! C5 R4 [ 以下各特效用的HTML代码相同:8 m& f4 j- m, x4 g8 }$ c( m
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
- h! e! C" i3 v. ]9 b2 ]4 b1. CSS动画边框1 h( n0 H; D% [
CSS代码:
" F9 Z2 D; H8 x2 J@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;
} 效果如下:, L& T& g' g! Z
/ m. R4 a% ~5 L! U% K; G4 m, W$ j: h% b% s# a
2. CSS图像边框. A O- f, g; ]$ {$ F0 ?# ?% \
CSS代码:
8 X: b" z2 S" X( L#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;
} 效果如下:. f9 T: Q8 u. H$ W- m
8 c6 q1 u+ h) J8 b- p
: G P2 c: l! k; x& g! H: _. e
3.CSS蛇式边框% U( l& @* O% S6 K( [; Z
CSS代码:
5 j- Z. i8 [/ k5 B. |* H& T#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;
} 效果如下:
" Y7 I c( H! I, W- d7 m* t
* \/ q9 I) k5 h$ }) r- D P& E
' ~9 W. F2 s+ I; z
4.CSS阶梯样式边框
6 q8 M, w, R& x; I1 R2 ZCSS代码:
0 d; i3 ?3 |4 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
} 效果如下:
- j3 K# G# S0 J" M8 H; _
. y7 a$ w& D# {8 c# T) D6 ]
( d' ^7 \; T* D- m( Z5.CSS只有阴影边框5 Z% F0 m! e, V% g
CSS代码:
( O9 g3 S. c/ W* 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;
} 效果如下:
% Q; N$ C8 q& O2 w- K
7 h$ q& V' |1 F- O& q* S" F; o. w$ U$ Q; l
6.CSS带阴影和轮廓的边框
4 {' U% Q5 o# @$ P8 JCSS代码:
9 V# T1 [" e8 {0 o#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;
} 效果如下:
5 V) C! F; P, W8 [$ f
0 ^0 u+ {" v4 x* b9 K9 M7 p* v& P
D0 R' }! L: F! Z+ ?7.CSS少量阴影和轮廓的边框
z% U2 M9 g' `9 @CSS代码:/ c# ^% H; S* _- 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;
} 效果如下:1 D& H$ `# o7 s9 ^4 B1 M- r
. M8 a/ t+ J2 T0 K) u, {9 o
, R6 Y3 k. P6 ~ \( {8.CSS带有阴影的双边框
- r: O& _1 {( j- v9 l' ^1 OCSS代码:
# X- n" N+ |! B" j+ s& @. S. G) L#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;
} 效果如下:
; M5 `# E8 X0 y( h
" N! ~# C+ q( h+ F7 \5 n: I. i x# A. N
9.CSS多色边框
8 {" j6 ^. a# R2 H1 e* pCSS代码:
2 L5 k% U# H1 Q! K7 B#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;
} 效果如下:
; k# u4 Z' G$ i1 H4 h6 y! O
|