CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。9 T, @, f- {+ z
以下各特效用的HTML代码相同:6 N& r0 x" s; E5 T# n0 s, m6 y
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
; x, p; V: [ c1. CSS动画边框6 W1 `9 b# S% c" [
CSS代码:
/ b8 m0 o: b& I2 h' p; Q6 A5 b0 g; Z@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;
} 效果如下:, P' T# \+ l5 D! g$ a6 i, a: r- \0 p
+ @' C5 {1 H" J8 O6 _7 s+ g- n2 i
_/ @( M' w9 L7 B& J2. CSS图像边框
: n: E# |1 o0 `8 N9 g# ACSS代码:
- |6 X- q5 I- A9 `: d 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;
} 效果如下:6 _+ F! I* Y+ l7 h
) B+ a/ \- t! i+ h
0 v7 t. q+ N/ c! ^9 \+ C3.CSS蛇式边框* p3 Y, a) N7 s6 b7 e
CSS代码:; f$ D- w. [; t! I1 {8 A: O, [
#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;
} 效果如下:
5 X Y ?; ^3 u
3 J5 I" C2 W/ x4 ?! x6 O# ]) ?, a. p, Q
4.CSS阶梯样式边框
3 p: P% [7 f) K3 E( zCSS代码:
/ m% V. L3 I! r#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
} 效果如下:+ }9 `* x) W1 ?- c. X. ~1 R+ m
" n1 E1 N, p1 X1 S' G i7 {5 T, E
9 ^0 h* @4 X' r/ V! n7 Z- T5.CSS只有阴影边框 L0 @ f* P( w% M$ D# ~+ I
CSS代码:
6 l& D; o4 h2 _$ G#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:/ m& H8 j& o- }2 u# f" m0 p
0 I7 ] l1 D, l
0 a. c$ e) m1 N8 U* c6.CSS带阴影和轮廓的边框
8 D- E' ]; O& y6 g) oCSS代码:( p" W4 O1 r5 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;
} 效果如下:
4 t' L& `- B/ Y. y1 P# v8 n
5 p5 n. b6 j& y$ R
) d" s7 ^, V0 r7 {! l- {; \/ K7.CSS少量阴影和轮廓的边框
{0 n2 R, L7 ]CSS代码:4 _9 ?& o' T C" K1 R/ v; k! i
#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;
} 效果如下:
4 _+ j9 W" ~1 H1 Y0 K0 I
. A- E7 {8 M% d2 s
! w) N" K) E+ u# H! v8.CSS带有阴影的双边框3 C7 |: \- Q3 Z ]1 ?3 F0 y
CSS代码:
7 D1 V" s6 G0 v+ Q# O ~3 `#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;
} 效果如下:
& E. ^& u0 y+ o/ h( W+ v; q
\6 F* f. i3 @' {( c, d1 b, v
9.CSS多色边框
' n& F7 b* R4 `8 cCSS代码:: v7 ?5 [2 N% ^. W6 P! I0 `5 ]
#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;
} 效果如下:7 x( ~( V2 R* T/ |
|