CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。5 U G4 X& D1 R$ ]
以下各特效用的HTML代码相同:
) W6 U- i& @" n8 Y0 `7 c. I<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> - F# u+ a9 T5 z/ `9 b
1. CSS动画边框
4 | S! F7 u8 b- {CSS代码:
$ j7 H. e0 e. A@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;
} 效果如下:
0 G$ ^/ Z* [6 j5 |" h+ C
, ^+ h4 A8 u4 n
4 D2 r- o0 Q$ Q/ U+ r+ _( T2. CSS图像边框; A) N, X. D7 _* F; o
CSS代码:
- W1 [% v6 p5 C, N" Z: h: X2 U#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;
} 效果如下:4 ~: T- o; U+ ?" o
7 k+ m1 t4 n' T" T7 Z5 |% {4 ^# r% I$ b1 V4 i
3.CSS蛇式边框8 M" `9 j' Q: M5 C2 A
CSS代码:7 P+ X4 ?5 n. p. u( [
#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;
} 效果如下:
4 m/ b4 z% l: \& F# h& I: G# }" ^& h2 C( X
3 l) U7 a; U0 U' A7 S% m" \; x$ K( R! R( N, k9 l
4.CSS阶梯样式边框# w2 R, s6 Y4 F, D$ s( T
CSS代码:
! N% S5 {7 `2 s' {& D+ F#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
} 效果如下:* H4 N. C/ ?0 H n+ z
( M& ^% `8 i3 i" y; Y6 |7 A% d
1 P4 s7 |7 X8 S& q# z
5.CSS只有阴影边框
% K! @( ]0 x2 X. y! h+ j* L. JCSS代码:
- ?8 _+ Y- n( E% z- 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;
} 效果如下:
7 @$ |- M$ f" M2 G+ [3 @
' D, N0 {/ h) \' s1 \
) K* W$ w" I E0 ?3 M6.CSS带阴影和轮廓的边框8 ^/ U) B# t+ h( R% e- N( M' A
CSS代码:
% \+ W. v; p6 j) W#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 B7 T$ w: P% z& A& `7 m
4 r; x* i1 m! ]$ N4 [# n
. _; V5 _+ }4 ?: p7.CSS少量阴影和轮廓的边框
; u9 z! C. E4 hCSS代码:
* h$ t" m h& }1 [#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;
} 效果如下:! M- M( {. x2 G' l: |% F
4 h8 |5 v3 f" C3 o0 M; f
6 l N. W9 ?0 d: ^8.CSS带有阴影的双边框
% ]- e8 S) M1 x6 L1 L; aCSS代码:
( ~& Z# Z! s5 E7 o% v#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;
} 效果如下:
# Z* R, s1 a6 u5 X9 V3 W: ?
' H* Z! _, w, T% ]% u5 v& D) |% Q# t4 x5 \" E* X
9.CSS多色边框$ g: ?3 S. ?( p. A8 q0 K0 ~4 u
CSS代码:
3 n+ e& s \/ e; C4 ]#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;
} 效果如下:0 r% t& r) q( N$ |
|