CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
m5 C& A) Y7 T2 y$ F4 Q) L0 b' r 以下各特效用的HTML代码相同:" j- W k( c0 f! {0 [+ s
- <div id="box">
- 编程适合那些有不同想法的人... <br/>
- 对于那些想要创造大事物并愿意改变世界的人们。
- </div>
, M9 r9 Z8 E% E* ]) u
1. CSS动画边框% Z3 b9 {" X& `8 D0 Q' S
CSS代码:, O. V- t' g7 M7 H/ Y7 ^
- @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;
- }
效果如下:
9 v+ ^9 M) u" W% B( D& K
. k! j7 p5 w) E& U# T/ C! J
! ]/ C& c" W7 P. J5 C" [2. CSS图像边框
( c) z, i) p9 E' F$ ?CSS代码:( d2 n5 R1 [9 R, }& k% ]9 M2 T, i% ?
- #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;
- }
效果如下:5 x, r% A! \ T, Q
0 a9 s H" P: ~- m. C" R
# @/ H- B. b a% Q. H6 x4 l" ^5 E3.CSS蛇式边框. f9 e5 ]1 {! R; M
CSS代码:
$ g7 Y H0 q0 M+ e3 e) a2 s- #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;
- }
效果如下:
8 {/ m% J9 Y- @/ u* f
" X, u3 y8 R" S. z& b
3 N7 u; U+ b5 ^) t2 b4.CSS阶梯样式边框* J( ~& ^; r9 s& T
CSS代码:5 b$ C. i2 c' T; f6 T
- #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
- }
效果如下:. ~; b: F. k) P6 |2 y; ^- ~
; y7 z" \: w& x0 o) z
, q" z6 ]9 D7 Q1 G# z5.CSS只有阴影边框5 Q/ J" u* n& `4 V8 G3 i! ]
CSS代码:
) F+ D( @% j! A+ [& {# m; i1 [: 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;
- }
效果如下:+ I5 Q- ~3 P M1 }% d! y, N7 U
4 ]" U. Q; A, I2 O* V& X( d9 _: X0 v: a6 U
6.CSS带阴影和轮廓的边框
* T% L& ]7 b3 k+ A7 i- @CSS代码:! {/ b0 c: o+ g5 f. 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;
- }
效果如下:
1 F( X$ c; r/ U( x
7 O! e1 t2 |7 h, }, a7 F2 m3 g ^ l+ G' w+ S' _* _4 h
7.CSS少量阴影和轮廓的边框
' p/ p6 b! I' I eCSS代码:
5 y) o7 \5 ?: n* F {/ p- #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' q. W+ e6 v
: b$ g+ q: f8 o7 H' K- D4 M
7 R1 d) U. z* h8.CSS带有阴影的双边框
& u( R8 Y4 b: SCSS代码:: @8 Z' E' x4 }" p9 Z
- #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;
- }
效果如下:2 p/ l3 G) Z0 p9 |3 p& H
8 b* @; j0 v: v( H3 I( ^( t
5 b! Y: a9 k! V5 g# Z$ P9.CSS多色边框
% V0 j2 p+ S; ?# G0 G2 _' L6 \CSS代码:
+ \' K& L8 a5 [0 c7 x1 `6 N6 |- #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;
- }
效果如下:
% n. C6 R% C, B& n. S! B/ _" h1 `
|