CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。4 k! Z4 d9 q4 S) m6 w
以下各特效用的HTML代码相同:# e: X9 X$ E& Y
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> . q, r$ `! X+ Q; ~! M, m4 g
1. CSS动画边框. |6 ~$ r) s" Q# }' k1 s5 I: ~
CSS代码:4 ~. h3 |# ?( W. G! u& B
@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;
} 效果如下:$ Y1 f& q9 g2 W3 i
! b+ E/ g; l& K M7 V* A/ f0 l, S4 f' {/ e; G9 j" A
2. CSS图像边框7 ^+ G7 c& C! T" E, u- Q: w4 N
CSS代码:
5 M7 t$ O+ E6 V/ y- x7 M#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;
} 效果如下:. o" }( |+ U- D7 v7 s: F. \, \9 c1 N
- P2 u4 \6 ]: T" ] f, H7 n( x2 D. V- J/ J! |& a" v
3.CSS蛇式边框0 J& y1 |) y3 @% ]! y$ p1 H% R. B
CSS代码:
`6 r! f. O8 M+ y#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;
} 效果如下:
. A: _3 o) j* o
9 P" ^2 y& m/ [1 b! S( V/ r( T u3 G: I7 ~9 p& q# v: i4 _
4.CSS阶梯样式边框
0 R2 a6 ~3 A, j. d, K+ u6 tCSS代码:
, b4 i+ _" {6 d9 [2 o |0 G* j: P#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
} 效果如下:
7 M" y9 X+ r# ~/ b+ u) h$ G4 Y8 ]
) q' [. d" p" \$ ]8 u+ p! E: C0 ?) d) h, y
5.CSS只有阴影边框
' M( E$ q$ c) {. z2 xCSS代码: V9 K4 V8 e% V" S, e0 y! c/ y
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:7 i6 J* a o* ~0 p6 w8 U
# ^, K; n0 ~1 Q3 g# N
2 ?, {9 h1 C7 R+ l% T
6.CSS带阴影和轮廓的边框5 k* ]: `: L0 X# W6 _6 i+ X
CSS代码:& C! O- [, \# x z7 m+ Q
#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;
} 效果如下:
- ]8 h) N5 r2 A5 g
& G" {# P# `" M( N) x7 Y/ [) B# k
7.CSS少量阴影和轮廓的边框
4 p3 z$ I7 K6 O/ U; ?. }- c3 oCSS代码:- B* z* l0 x% W( d2 x- a5 R
#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;
} 效果如下:
x- u& J7 U" T8 L1 H# g$ ?
1 C- U( ?* N- w
& y* e: F' r( @2 P5 X8.CSS带有阴影的双边框
7 I7 \& w. t7 X9 c6 w9 i" b0 DCSS代码:
% A- B* h! t y4 _$ C# g( I$ }#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;
} 效果如下:( s* f+ h5 m4 {& h
4 l" K( Q! U3 T' G0 @6 m# F
5 U1 ~5 {: J& T2 c9.CSS多色边框
; J- n& r( S- \2 ECSS代码:, |( H5 e0 H, n% W7 Z
#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;
} 效果如下:4 I; ]. A' r4 Y* v* }
|