CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
; h( ~* a% g$ ~2 k! X 以下各特效用的HTML代码相同:
5 Y, W0 m" S1 O$ u<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
' P& Q$ Z+ k' l2 p. t) H1. CSS动画边框
8 c1 x* _3 s6 V) n! m2 |, U" q$ n+ |6 lCSS代码:
; J! t& |6 c( f7 H/ n0 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;
} 效果如下:
% Q* |0 L& t9 [1 e, q
% [% l6 V0 E4 T8 r; q% K
6 O5 ~$ L9 z& \" q3 T% D. P# i
2. CSS图像边框
! s+ i" N b/ _CSS代码:/ g M; N$ e/ @+ 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;
} 效果如下:: Q! W7 T: H" _ a( @6 o3 }) i
3 P( ^& [9 \ ~( P7 S( Q* r2 F
7 ~5 Q N, l" j* @* e3 B! Y5 g3.CSS蛇式边框* f4 x& x+ w/ n- q% t. B# r1 @
CSS代码:
0 B; q5 L" C$ R% |! B8 B( ^8 k# C#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;
} 效果如下:
/ K7 X5 E8 z$ A: A% C
+ U9 l% R; u1 ? ]2 p! Y
* D) v- q- z/ ?/ f6 J8 a5 W: w4.CSS阶梯样式边框
) G" u! G# \& \8 c% E Z: tCSS代码:
. F. p8 c* y Y# G" n6 f6 L#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
} 效果如下:+ H p6 g0 I' \
9 G) f+ R" {: \' G
0 C, H! _& N; ~; a7 E; S
5.CSS只有阴影边框
% e8 n3 N+ V. |2 E% Y2 @CSS代码:
y* R7 V( Q' X* V& S! 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;
} 效果如下:
# f! n1 \- ~ P" r; E4 w
$ Z7 n% U$ y8 ?( A: G7 d
* p. g+ k* m. M( q* P
6.CSS带阴影和轮廓的边框
' C; \) H* F7 {( f+ FCSS代码:
7 t' j! H; g' O% M#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;
} 效果如下:; _* @" w5 K; \% n, b0 g
4 N# Q* @7 _9 r7 U- q) d+ T) X
/ g! Q! q8 z' b5 W6 P" v7.CSS少量阴影和轮廓的边框% `5 \- c4 |5 R% E* u' ~% s
CSS代码:. `! d. d. v3 q( G
#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;
} 效果如下:
( V, `% C c/ O S* ^& [
3 B- r c4 V% `5 @4 b9 T
, Q: o* P! {/ c w8.CSS带有阴影的双边框
* a! i. {. W5 p2 l r( M4 s0 A) jCSS代码:- B3 a+ X5 S( @8 _/ A! r; w
#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;
} 效果如下:& u! J3 w! n. Q) e/ ?, h e
5 A; o, J" Y6 v0 }. @6 [
; T2 Y+ ?4 m! l/ o- d: `! q9.CSS多色边框! U; F: @: J& h- Q$ P, }$ S; ~+ C- [
CSS代码:
* F, I" I. ~- o H4 \3 |1 ^#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 h9 p2 R6 A" N( R- {! J
|