CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
: L: D' W ^* k! q% r$ C5 H 以下各特效用的HTML代码相同:
/ |8 e) A9 S& ~. { p, A; I<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 5 {6 F. ` d7 x' K
1. CSS动画边框
. h; I# n' t. C- E4 V) b' WCSS代码:
* X { z. r2 a0 a1 D! e6 r+ [( t@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;
} 效果如下:& {" Z ]2 C& L/ R1 h
8 X) ?3 C& D- A W4 k6 U; Y o
. K- [2 t; @- m2. CSS图像边框
. U1 | p/ E! ], M2 I4 i! j+ J( ?CSS代码:
. ]3 z1 @/ Y* h+ A. m' M1 R#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;
} 效果如下:8 x% O; f1 l% x- g
' b6 l) E3 ^+ |# d! l H. ^" q* _
3.CSS蛇式边框
- y/ p0 u7 z5 ^$ P" m5 j) WCSS代码:
9 q" O9 `% p& a#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 u8 I% S9 R/ a7 O1 H
; x% k& e, q+ n/ [. j
+ C2 b' {) ?+ |4 g
4.CSS阶梯样式边框
) @4 K9 N" ~5 rCSS代码:
. ~$ F9 n M1 F6 u) C( D#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
} 效果如下:' p6 Z; f" }& G/ Q- I/ M( |
/ ?9 @/ [, k' R
2 b, a2 I; g+ I9 _: `5.CSS只有阴影边框
: E8 v1 r4 [. K, n4 F4 DCSS代码:! f' U' a# a% W7 w
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下: q( e' j7 C9 E+ H
( g1 o9 r/ m, w6 t/ I/ Y- V: _; x% V( G5 s
6.CSS带阴影和轮廓的边框' I/ l; b9 O. p; u b
CSS代码:
) W8 w T3 d& }/ K, E8 K4 G+ 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;
} 效果如下:3 W d6 `* A! u: f$ h, ?7 q6 C8 \* f6 w
" l# ?9 l% v& H8 d% W8 n7 p7 q6 ^8 l" b. x) @
7.CSS少量阴影和轮廓的边框
7 {' J6 s0 u% J2 A2 H ~CSS代码:
3 D. {$ v" {! o9 W2 ^#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;
} 效果如下:
( _: C, L8 B+ c$ P+ Q1 ?* T; Y% Q& B
- }+ F( K& k; {1 ~! o5 R
7 T% b) V0 {, V! A% `+ Z
8.CSS带有阴影的双边框( ]8 K$ A( i" n* Q) \" [, ?
CSS代码:
3 I/ J D3 o0 |( ^3 U; {#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;
} 效果如下:# B% y `. Y# R1 j& r0 I G. k
- ^& l: b- j2 D; C
+ h( {- A' r9 h S
9.CSS多色边框
2 P$ y6 N- m o, ]. X! \5 q: @9 aCSS代码:& g2 x, N$ b9 z+ 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;
} 效果如下:% r! `5 i, a* }: f
|