CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
5 ~9 ~0 ~7 t. M: o2 _& A, z 以下各特效用的HTML代码相同:
4 k6 B# Z2 m3 O6 b1 _% t<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> " S9 V0 U l4 `7 y
1. CSS动画边框7 x7 S% H1 M* A0 V
CSS代码:
% C8 X) {" J3 ?: U& ?9 M: M, X- s@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;
} 效果如下:
5 Q% c) g- \8 L/ m9 ^
" x7 C- L. r% `/ s: R; _* Z
, m4 b% n; A4 i9 f, A2. CSS图像边框
8 z! d- F: v7 v9 _4 |! i; eCSS代码:" I# ~5 d9 y! x5 `0 r8 q
#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;
} 效果如下:
" Z6 g+ c/ T4 H& l$ |: E( b
6 v) r3 ` L: ~
- T, h6 q$ Z, P3 l1 y3.CSS蛇式边框
" x$ p0 M C+ Z, ^3 w P, H$ Q# FCSS代码:4 k1 @* ]$ q9 b& a: Q
#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;
} 效果如下:9 h" v5 A9 s7 Y
E8 @+ C# A% n% a( S+ U0 u
# N2 }7 Z. g6 j9 U6 G
4.CSS阶梯样式边框9 }/ F$ V! _4 W, L" P" f
CSS代码:1 ?+ `5 F/ ?8 L: v; q
#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
} 效果如下:
! m6 a- l" Y' C- w& G
5 Y2 `' A5 d* C g
$ _, X1 v0 E3 u* N5.CSS只有阴影边框1 `: k- n! u3 S$ T R/ m
CSS代码:1 ]5 U/ u* L+ j* ?1 h; Z u
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
; z A# a; k$ K
& p# W f& O6 `7 q- _$ b8 P. ~& y# \
! ?( \3 j6 M2 f1 F2 F6.CSS带阴影和轮廓的边框
1 f1 y/ ]0 d. Y) @3 mCSS代码:
) ~$ \. L* h% [( J: d#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;
} 效果如下:. }" Q+ V' {$ q1 F
7 g- b& L L) Y& a6 C# `- L. p
# e$ L( o/ q# O3 z+ V
7.CSS少量阴影和轮廓的边框( w$ _0 M8 o; @4 c. C+ X8 ]4 u1 g
CSS代码:( g; R6 N( \+ G
#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;
} 效果如下:
# e) i2 l" k) d# h! P
* H4 q: c+ E# Q, B* E
5 B3 w ~' |0 f* ]; O8.CSS带有阴影的双边框/ x7 M: ` m7 M/ c$ c7 P0 z$ e! T
CSS代码:- ]( u. D4 _( L! h/ k
#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;
} 效果如下:
4 H2 d' v# T8 ^, `. o2 p4 y! I
7 y' |' y+ X3 m) |8 G
p5 U# C5 a/ @" V! O* g. h& F9 \ _9.CSS多色边框* ^, R; r$ e8 W1 N% P; L; f
CSS代码:' k8 H8 X+ \0 ]" D* O I) f
#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;
} 效果如下:8 {4 e# u& y* U( G
|