CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
' B# }: D3 ^+ x5 Y& T# i& B$ G 以下各特效用的HTML代码相同:& s# d6 n0 c h7 H1 V) u
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 6 n* b7 l; r7 M( h2 j9 R
1. CSS动画边框
8 q8 Q2 m5 s5 z5 I) KCSS代码:
$ L7 I1 Q: ^& b4 o; e# t@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;
} 效果如下:. l5 _( G/ q l
' q9 d F. Q; A6 I3 I1 W6 C
5 X7 ^% `7 S4 ]6 M' q( |2. CSS图像边框
1 S0 q, x" d3 @; _CSS代码:
" ?2 S3 a3 h6 P" {0 r, o6 K6 ^#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;
} 效果如下:6 T8 ~# |9 ]/ \4 C! L/ G6 d. {
6 D% s- h- O/ }3 ~
8 X! G0 t$ @. @$ M
3.CSS蛇式边框
; c: m$ r2 b$ wCSS代码:8 k6 \6 N2 r. u* i
#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;
} 效果如下:1 l( [& ~! j' V X, }9 E0 J
' ~. D/ s- c! Z! G
/ j! d- T/ Y2 J& Z4 o, O4.CSS阶梯样式边框 ?$ u+ Q# K6 Q
CSS代码:
, y# p2 L9 w2 I0 Y#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
} 效果如下:. n# B9 @6 D' K, J' {
! @9 k0 ^3 L! K
4 \1 [7 @7 ]$ Q
5.CSS只有阴影边框
: [7 X5 y# g% |; eCSS代码:- b& C/ j; Z5 X, I
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
' L1 Q% g+ h( \/ q1 E6 @$ a( |
$ y3 u8 p$ s3 p/ b! r* C8 a( R% R5 \; v* w, V( ]8 v
6.CSS带阴影和轮廓的边框: c* D- q1 e. F$ s2 t2 @, \0 P7 ~
CSS代码:7 h% K" P$ f* \) \
#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;
} 效果如下:
! n9 c0 z' H* R1 P
- g& F2 f* y& \/ i! v( j
+ D2 m+ V0 y- W" o' \- M
7.CSS少量阴影和轮廓的边框
1 P5 M, \* l8 iCSS代码:
! J1 [7 X4 O" N4 C#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;
} 效果如下:
; T$ [" x3 V o. l) Z# B; X
S5 N( Z7 j7 ^% I$ ^* T
1 u) k, Y3 d: l" _% l0 q8.CSS带有阴影的双边框6 T; w- H4 T' K+ K1 Y% D T* w% n0 k& [
CSS代码:
% z7 ^/ Z% Z" U$ a2 t#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;
} 效果如下:
. A `5 c. S0 {/ {# i* i
, [2 Q% c% {! w% P( c+ |- [6 D/ h$ M
9.CSS多色边框3 t2 c* O3 U: f7 X0 Z- \
CSS代码: t U( q* a. J1 x
#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;
} 效果如下:/ j, x1 F4 D' @. q" A. {( w% m
|