CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
) g. R6 w1 m- G3 u& g& s( G 以下各特效用的HTML代码相同:( U5 w1 _7 j9 d
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> , `7 U% q! t+ b" L. \0 z
1. CSS动画边框
" h( j% k( u; f9 R- `CSS代码:
# |! J8 k0 q/ }@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;
} 效果如下:& v/ Q* D' c4 H$ [, B' k$ j1 H) C
' a9 V6 v; o' h3 R" H" c1 S& p/ v w! W5 {
2. CSS图像边框! n- y) b4 x, h4 t1 j4 b
CSS代码:" |/ I+ L5 s9 _3 F6 n
#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;
} 效果如下:
* i# [& b/ O: S6 G; W
; E/ x1 [% f* V* P
. }' s8 _ e( i' R0 a$ J
3.CSS蛇式边框
7 U1 O6 T s& D2 ]0 @5 ^5 X% bCSS代码:
: s! D% K6 T3 q% H* J) a#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;
} 效果如下:& f8 M0 F6 J) u4 J$ D* F
. c& G0 [% f0 I2 B6 ^6 ]0 m5 B; |. `( W1 O9 ?9 s* n" S1 X
4.CSS阶梯样式边框9 c6 p% \! @+ S1 \7 z
CSS代码:
O0 C9 z8 S& r; e#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
} 效果如下:
; |% j9 x) ^7 J8 f
9 V$ i" f6 ~, S# _ p7 O
% L5 f$ g, Z" x; g9 k9 |
5.CSS只有阴影边框
4 m" o3 E9 d7 u! i' I: }+ Y5 {; @CSS代码:
3 g$ M: C% T) J7 }! u+ O#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:! A+ {/ X3 b% O
D" u* d! b+ M+ N/ O5 E3 T3 y+ L! Y5 _ ]8 |
6.CSS带阴影和轮廓的边框
9 \4 W- Q6 D3 c8 m6 u! k! NCSS代码:9 o0 o) C% G8 T# v" X2 @7 Q
#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;
} 效果如下:- ?8 g# m, M( g% l3 c" [
2 r$ `. q! Z/ n9 J5 f4 a7 }' k; E
/ i$ A# N- ~' L# Y! B5 x" V7.CSS少量阴影和轮廓的边框
0 L1 ^) J* ^- s' N. ]CSS代码:( d* I0 p% E" x b$ |
#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;
} 效果如下:
% R" o" ^/ l) c. \0 A" ]- A
/ H/ i" O; k8 ^ h6 n7 B
$ D! N( y. n$ }! E' X/ C8.CSS带有阴影的双边框0 C* y4 h" p" x6 |: h
CSS代码:! R5 L. t7 d/ [) D; Q
#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;
} 效果如下:
, L: M6 ^" \ @: {& z6 u6 c
/ Q$ l4 h. N5 B- z( y( N
* c& W8 {7 Q8 F, B0 g& Q2 W; x9.CSS多色边框
" s5 w4 e* A0 x5 z' oCSS代码:
9 Q5 [. T7 V5 z3 B+ z2 C#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;
} 效果如下:
' b1 ~; K( V' _: d5 J
|