CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。: j) V8 _9 d2 t; C0 }" w
以下各特效用的HTML代码相同:
8 C' i* b1 n D# @* o" Z<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ) N4 S# B3 v' Y6 F2 o9 F8 G# `3 j
1. CSS动画边框5 y5 H' `; C5 z. l% l L
CSS代码:1 { q2 e2 ]! V, @' Y8 Y3 M( r
@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;
} 效果如下:
/ C2 O* I8 y9 |7 B
: ~( I. E7 @4 H5 \8 {( w3 x8 J: `4 g, K. h: W* a
2. CSS图像边框
" a3 R) [2 r9 b1 G* l$ G0 ^CSS代码:/ H+ R* _, G A; x: _/ U
#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;
} 效果如下:& r1 s- N. U0 `( m% K
, H: p* N/ w* _4 }3 U# b' Z3 D: I3 ]: t, |6 o, l
3.CSS蛇式边框
4 ~0 O( o8 F- XCSS代码:
8 M0 n$ u2 U& M/ p#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;
} 效果如下:5 d# y5 p# m) t6 d8 W# d% d8 I
6 G7 a) A' F5 x8 C6 x8 R' h" e
7 t3 v$ i. N u) {4 T( w4.CSS阶梯样式边框
s& k: M" Q( A! KCSS代码:
) P$ H B1 B$ l, c#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
} 效果如下:
7 n% C8 C( Z- V" ^
" S. p! _+ R6 Q. L5 h! T
, i, \# _3 y% ~5.CSS只有阴影边框
) e% H a+ B5 {5 ?CSS代码:/ A. [& j# V# 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;
} 效果如下:
- N u# z8 ?, ?0 G. x- q
7 m6 s/ B4 M4 s
- w6 T: B; E" p d$ @
6.CSS带阴影和轮廓的边框0 Y: U/ d6 m9 d$ l
CSS代码:
% l+ m+ Y) c1 b, m" {: a& M5 ^/ c' @#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;
} 效果如下:( C+ w# |( v5 B9 O: H1 R$ u
/ F, O: j' w0 I* ^9 m3 v" y
! z% Y& s7 l# E
7.CSS少量阴影和轮廓的边框
6 h1 f6 u* D# q# l1 KCSS代码:, _/ O2 ]3 d2 y" s
#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;
} 效果如下:; s& o: \$ G+ H$ ~+ {. P" B0 Z
8 T3 O: I) z6 C d! C, {% r
. y3 w5 [2 O$ ~) L5 g4 u W* f5 ]
8.CSS带有阴影的双边框
. A4 W8 R# M: i- QCSS代码:
8 g- E& U$ ?. l& Z7 E( u#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;
} 效果如下:" P8 j( f" }3 @% ~! t' E6 ?
]" k+ d" w# f% l, o; V% I3 `3 y. \ E
9.CSS多色边框- L$ R0 v/ v6 `
CSS代码:, T3 U* t6 u6 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;
} 效果如下:2 ?8 K0 p9 Y* t* i
|