CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
5 d! P6 }# `: f; q- y 以下各特效用的HTML代码相同:
$ h; ^& N3 S6 @' D1 G3 D" l3 v<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
" `& o! u2 U0 S% B4 G1. CSS动画边框2 H* p' q0 N$ t
CSS代码: R1 G& [: ^4 j) F' B, D7 y
@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;
} 效果如下:! x' k, b/ t& t. B8 D8 j; \
+ k; t/ C* y* L9 v
' N5 N0 }+ }* Z' Z9 s, ~! V2. CSS图像边框
% ]; E# e2 m2 s% u; |CSS代码:
# {# Y( `) T' C6 N* A#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;
} 效果如下:# g# {9 D! g: r6 \ ~
* t B* n7 i( P9 `0 Y
- c+ r4 H: T$ h2 P2 I3.CSS蛇式边框
* V( U! r# Q9 c4 x8 j# e% q7 ICSS代码:
8 D8 }0 ~- R9 m" p4 X4 w: g#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;
} 效果如下:
+ j& H, z7 K$ A% Y
5 O+ U$ s; p7 m; t- u: _( g5 u5 F9 c& o% U% |7 b. F) R/ h: o
4.CSS阶梯样式边框6 J" g$ E/ v2 g
CSS代码:1 b9 ]! i9 \/ {0 j" s& E( T4 R
#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
} 效果如下:
* g0 c9 m5 v2 v/ }0 |4 H0 j- h
; ]8 L) F4 Y Z% @- K
* O. Q" C0 H+ J8 _- h3 q$ \ u8 U
5.CSS只有阴影边框& P0 v: [! z) A: V9 P
CSS代码: ?( a( N) x6 h S& T7 |) `
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
9 o7 ]5 e! _' l5 I3 X. s2 ?
- y. V2 }: K! n4 m3 [5 g6 p; r9 k
) w# V* {8 j2 N0 I9 O
6.CSS带阴影和轮廓的边框1 G# ?0 q# |7 c# d
CSS代码:
: O3 }+ }8 q- H3 w" P#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;
} 效果如下:
; V/ C9 K5 q1 }, y
7 _& y, n" \2 i' u8 ~
4 j; k- r* Q0 u1 G+ h7.CSS少量阴影和轮廓的边框) ?/ E1 P: e/ D
CSS代码:
4 F/ i y; p# t9 a, N& w#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;
} 效果如下:; o8 ]+ U# H2 a& y6 d. r1 Q& n
; b5 w+ b" N% ^5 h! l: ^' B1 v f
7 d5 u& q: u M7 h8.CSS带有阴影的双边框; u" O; w/ ]7 ^' F
CSS代码:
. l( }% S: |# D6 R#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;
} 效果如下:$ t1 _' X' T4 T1 I% h( c5 F
w- Q5 x5 k& a( W. K
m" @' @% f$ n9 \9.CSS多色边框
4 T8 \! a, M( Z8 {" F' V0 @CSS代码:
. o% `8 v, Q" Q- D% E+ @#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;
} 效果如下:8 i, X7 D& |8 E7 o
|