CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
# R9 H6 O, S4 ~, m 以下各特效用的HTML代码相同:
4 _4 F6 W1 x" c: { @<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> : v& ]. Q& a8 O# J) t+ S- d) i
1. CSS动画边框3 h: k6 K# C# n. K% o' S; y
CSS代码:' s" N( w: a2 L: f N3 \" 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;
} 效果如下:4 P4 b, A4 O @5 T- I3 T$ B
+ P7 ~2 c9 O$ t: |& R1 D4 H. i/ V& O+ u9 y4 ^1 e$ H* Z, ~1 }+ d* C
2. CSS图像边框
8 Y6 [" s7 L/ ACSS代码:
5 Y2 J, h# _5 i/ _$ \; 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;
} 效果如下:
( y, S$ B- X" L0 ]
* D! A/ E, O' b O& W* ?
6 A( T- `( j. |& ~
3.CSS蛇式边框1 ?0 d" M9 a9 `5 Y7 ~& p
CSS代码:
7 o/ A# {) W% k#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;
} 效果如下:
E `9 p/ v4 a* [; }! _& E
1 R: n$ T0 Y Z1 @2 |/ b
2 |% [' l3 q7 ^6 I4.CSS阶梯样式边框
. s. D5 J, T6 l3 [CSS代码:
( G: V" I1 I+ d) G( A$ [' \#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
} 效果如下:
% j8 s% X$ @: A+ D2 h( N- N+ @
9 |1 ?& s! I" Q j( b
' o6 N/ H, U. N& ~9 R5.CSS只有阴影边框! |9 S0 `& Y( S( G; V
CSS代码:
! s! a: I3 `# o! y1 y& d# D, H#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:) L. Z# [6 B0 s# a0 G8 `2 K
7 A$ e6 c, j# |+ y: R
7 R7 A8 Z# g* c% _( i6.CSS带阴影和轮廓的边框
7 ~2 s) h* @- k9 e5 cCSS代码:
& {- j r# P7 `% N W6 ~6 x#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;
} 效果如下:1 Y1 x. K/ z/ a' Y' p1 V; Z
6 G( h& `9 u; F& e$ W- W$ z$ Y5 Z3 G1 b9 @# {& p. w p
7.CSS少量阴影和轮廓的边框
% f. }* ~) c" \/ V5 y3 L$ ]% SCSS代码:' G4 H* _" A& ~; `& N, P
#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;
} 效果如下:5 E4 R7 O4 \1 r3 K" R Q. T
' e, M- w5 v. m
9 {) V$ x; Y# I/ N. _8.CSS带有阴影的双边框
4 ?+ s0 O! _9 X# Y% { OCSS代码:
* Y5 k, Z( [6 |7 v#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;
} 效果如下:: F, D/ k, J) Q# P0 u
+ k3 s# `2 o/ i$ g
9 C. T3 y8 V" n* K) ]5 ]$ Z9.CSS多色边框
5 \2 J0 r% {$ [4 Z- C9 i3 CCSS代码:
. a# F1 l& B% x! s1 i- D. S1 `#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 r8 E# H& }* }5 L# L, l1 `" ~
|