CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
) p5 | q0 s! J2 Z" X1 u4 j 以下各特效用的HTML代码相同:8 Y( s7 N- u8 s: s/ z8 u/ {
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> , k! t1 g* |( t/ t7 E Y
1. CSS动画边框, C! j! K F' }; ]
CSS代码:
6 c2 [2 S% M- q; R+ G@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 I i& J6 j5 {; k- p
+ X0 Z, C- `8 p1 P: B7 L
; B% F8 j2 c" M7 ?5 ~
2. CSS图像边框, n4 |, p$ w" S0 ?; _
CSS代码:
, s G, e" [; \0 t$ q, X7 L9 u#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;
} 效果如下:
4 p9 A$ | i5 e# C6 o
/ G0 S2 [0 K( L4 e) B; k# n
. e4 y7 e8 E' X5 P, e3.CSS蛇式边框
' {- L" L: [1 A( CCSS代码:) T! Z+ s0 ]4 d: N
#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;
} 效果如下:) Y2 ]4 Q v8 j, g4 F
: Y4 P: B$ W8 |7 ]6 x% D1 Z1 V
9 X4 j; T; T- {( ~4.CSS阶梯样式边框1 Z) O9 T# |3 t8 H, c9 e+ d" Z! d
CSS代码:- [; r1 e6 j4 d2 h# e, w- t+ I7 o' u3 k3 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 w3 g0 C9 V( y$ I q5 N
H3 ]) Q% u2 i* {" h2 ]
! l9 w' B& X% G8 L U! q5.CSS只有阴影边框
1 Z8 Y! r- O3 e6 JCSS代码:
5 Q( h- ~. K4 |/ E: d' T8 x/ N#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:3 v2 `. q% f$ M$ _# _6 a
$ y% ~/ F5 X9 B* Y% v$ m
" k5 ^* C7 J/ w- E6.CSS带阴影和轮廓的边框5 j' H7 z. d" F$ F# W/ {1 D# C9 @
CSS代码:5 h& }8 D# X; p- b
#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;
} 效果如下:- C6 N6 h6 f3 k# L l
, H% c$ f4 Q C% ^! I- ?$ _1 W
' F# D7 y9 H2 p& P& k+ G% V w# w
7.CSS少量阴影和轮廓的边框6 d u9 v" K4 V$ d4 d& S0 u, M3 l
CSS代码:
, j* E* ~# B, n2 Z9 v0 z#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;
} 效果如下:
6 {. d. Q4 A' D' t6 m* q
& X0 v$ `& n5 Q+ V' r; C* Q( ^9 J3 A/ b1 _* S6 z
8.CSS带有阴影的双边框9 a) b* X* f; N) m
CSS代码:
9 H1 o+ @6 R4 U% ~; ?2 J8 x, ^#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;
} 效果如下:5 B; z+ z. \: ~- ]* q
^- U7 a2 ^: ^6 P! R7 ~- y2 T* [% l1 J2 |+ Z
9.CSS多色边框8 U+ ?% W$ `8 d3 [# |& L7 J
CSS代码:
: v" j: T4 k f4 m) a8 R/ n4 B#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 J8 E% M" M1 u0 R8 D, i( J/ C
|