CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
" j- E: F: ?# `4 C& C- J- Z 以下各特效用的HTML代码相同:/ @, P3 M/ N: \2 D' U& y+ |
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
' z# _" d- d V# ], a' f1. CSS动画边框7 w: _6 @) a+ b
CSS代码:; p0 y( @" s$ ~$ a5 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;
} 效果如下:, N6 C4 L" o4 h' t3 o; X, g% l
, A2 |: I, v5 t3 X; x- i
8 }, \1 `: A: t+ G/ \+ x! m0 i5 u2. CSS图像边框
# j9 B" p- L8 d0 a" s+ [CSS代码:) o0 X5 L( Z1 X4 _/ W& F) Y& k
#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;
} 效果如下:, ^3 ]! D8 u. g( l! `( S
; I; m$ U% p0 u( j+ ?2 V7 g
# A+ C' Z# |8 M* q& c% i3.CSS蛇式边框 J+ M: r1 r1 V) [
CSS代码:
0 }5 G% p& K( Z# e. w#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;
} 效果如下:9 z/ |9 G$ S. ^( v( l6 Z( H$ Q0 i
t$ z7 t. `2 @6 K( b( W# @2 T+ U# h- M- Q
4.CSS阶梯样式边框) ]5 |. _' D/ u+ f ^
CSS代码:
! u+ g/ {# u# n( b#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
} 效果如下:/ `6 D _. h! @* T
3 C* V9 U$ Z7 ]5 ]& h) r' C. y6 k# V3 _6 {5 r
5.CSS只有阴影边框
% H9 Z; e+ b( FCSS代码: a! U# _9 y: q0 M/ l% r1 z$ s4 }
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:; W, V K, h3 g5 ^, I
" f; X) D1 G0 X$ C6 b: O& N
, i; x! ?6 z1 {7 |: X! f6.CSS带阴影和轮廓的边框
1 s% _7 G2 K% UCSS代码:' D& q* O1 G1 T: q# r
#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;
} 效果如下:# e0 l7 `0 z: q) l' h E
+ r0 K$ W4 V8 J* G- m( N" E3 l q3 i2 m& G F, ~1 g+ Y' {
7.CSS少量阴影和轮廓的边框) |! O2 A H7 e
CSS代码:
6 N0 v8 _) p* O. @& O#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;
} 效果如下:
% f1 K+ C; t; I
/ c+ W- i, P9 v
6 B( \0 ~: ]6 n5 o1 e% |6 M8.CSS带有阴影的双边框. \+ \# @6 n( a" K
CSS代码:
3 \0 g2 H8 L' B# h" ]2 p/ P/ ~#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;
} 效果如下:
" W& ?4 D. ~& E7 H, j
1 U; Z8 P K! Z* l
% s, Z8 k: N: ?/ p) I! t* ~" W E9.CSS多色边框 @0 E$ b! ~; Y3 [# q) {1 Y3 d
CSS代码:$ b, K' W0 i6 p) K0 K, Z
#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;
} 效果如下:
/ l" z8 r% Q8 g, k J S+ i3 R3 t
|