CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
1 K* f1 C. y0 v0 {4 M 以下各特效用的HTML代码相同:
! e" d+ c) q9 r( h<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> : N& V5 M: ]2 o; b" C% D
1. CSS动画边框
& a3 q, Y; c; DCSS代码:
# h3 w1 K' i# X( u7 ?5 |& D@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;
} 效果如下:
) i4 t* D7 q& z8 b1 O( O- t5 F: s( ]
/ ]0 Y' K" [7 U
' m6 z; i8 O8 O+ \2 D; `2. CSS图像边框$ Q1 U: g: N- M% ]$ M6 {* f% W4 h
CSS代码:# A% R! C0 L2 M# p' |+ h
#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;
} 效果如下:7 d3 ^3 j; F# |3 j( o% x
( }- G' x$ R% {
- P" `0 Z6 Y. l7 X1 {3.CSS蛇式边框
2 ^% ~3 {2 }" Y0 T8 N+ hCSS代码:2 A* B1 D) F4 N7 D- i
#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;
} 效果如下:
F- W$ q! @# ~4 b' B& r
% A" ?' r5 b# P
& w7 n& m+ c; I5 }" Y0 ?' }4.CSS阶梯样式边框
, q' M6 E/ {9 P8 m/ C/ Q) H2 }CSS代码:
% H* H: _8 U l h: j* g( R- U9 Y: p' N#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
} 效果如下:
; q; d. ?8 n" a' e h
6 x2 {4 w! p' ]
7 F3 N- q: E$ ^8 c1 r1 Q; F: l+ v( a
5.CSS只有阴影边框6 a0 l) E1 m( N7 x
CSS代码:* I3 b1 t' O: U* p- y+ ?* F4 |5 |5 ^
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:% N! ~7 M, M( I' r8 s8 u
2 o/ v- h% o2 m
+ f' r7 T; }) `5 p# L( m6.CSS带阴影和轮廓的边框' E2 l% u& ]) R# L
CSS代码:
1 Y. L( }; d- W- M- o#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;
} 效果如下:: h& w4 H& Z+ ~
6 n6 R. ?; n8 W" K/ A0 _/ g. k7 H
* x6 X) J2 p8 _7.CSS少量阴影和轮廓的边框/ y1 F8 `% F" F/ G
CSS代码:: C& S9 H, V3 i' q2 O( A. @
#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;
} 效果如下:- u6 K4 ]* ^ O$ V. ^# b+ \+ l1 }
: c; o. y" V; |
7 A3 A5 X4 b* u) O" V d8.CSS带有阴影的双边框$ n, z( g7 n8 A
CSS代码:' m/ r' z# }# C
#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;
} 效果如下:# x9 N' q7 b+ P: T8 t, Q
; \7 U9 l. G- d _) {! W" s
% j+ s1 Z' @' o' B( z2 y9 d
9.CSS多色边框
8 {/ u$ c4 l S* u& WCSS代码:. f" l& q( e3 O+ l4 W
#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;
} 效果如下:! ~# `- C' G: S) l
|