CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
* Y# w, i% `# J. s5 w! J! T6 H$ ^ 以下各特效用的HTML代码相同:
. \- Y4 S s# q2 F<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
% y# C2 ^9 a0 k) f( J1. CSS动画边框0 X+ B# w% b. p% e: C) L
CSS代码:9 V2 E% W+ _. u& |; p, |$ 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;
} 效果如下:
4 f) Q F! G6 P! g# x4 ]
. p; ]' l1 z; f# ~2 e5 h
, s. g) P9 R; X0 H# z$ Y
2. CSS图像边框
2 C( h0 s0 U/ H) w7 p& @6 rCSS代码:" B% Z1 J+ B+ 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;
} 效果如下:5 @6 {5 P! s: |& k" F [
, @$ {) m4 m3 h" z" i, L: f/ `% J- U( ?2 i/ D; Y
3.CSS蛇式边框) a' ]9 _+ ]: F4 h
CSS代码:* K7 T R* n" I5 N
#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;
} 效果如下:
" B$ @) {$ V& D) J g$ i$ d
: k: _+ U9 B7 O3 O: z. _$ g& v- q0 c) y9 p8 |% x# p) [
4.CSS阶梯样式边框" i9 c& H! N' z4 {- \9 D2 a4 c
CSS代码:
5 ]6 p# o% B% H" h p2 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
} 效果如下:
1 v3 S. I1 X, I/ T6 P0 S( o- H+ l
+ Z2 V' ?; E2 a6 o) m4 i! w
1 ?" k8 V; j/ Q6 w( f
5.CSS只有阴影边框# Z4 J) n5 S- j; {% A
CSS代码:2 d" w% g6 T5 i" ^3 ]
#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! p3 Y- W( @/ K
2 H+ f+ L! ^! N2 i
h1 P8 I' q) L: c- ]" r8 X6.CSS带阴影和轮廓的边框& w& T5 D4 b0 b4 B" F) A
CSS代码:8 O1 [4 _) P/ 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;
} 效果如下:
# Z! i& P$ { i( T. G! f
0 d w' h' s8 l7 ]* V2 d4 ?7 C: v
R3 |! n. x6 \. S* [) l7 q: j) _
7.CSS少量阴影和轮廓的边框
1 ?8 h4 {* L- M* p8 KCSS代码:$ T7 [- r0 c9 E+ r- \5 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;
} 效果如下:9 U1 z5 z& R9 W
! k: P' C2 G# p8 u
8 d Z$ G* E4 x- z& M5 y: W8.CSS带有阴影的双边框1 @2 ^, ?! s. i# }: i5 o
CSS代码:2 G: j0 U* u& s: n
#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;
} 效果如下:; T3 l9 D' z* d; X" h7 A8 |
4 @2 R3 e- `0 e G0 g
( c$ @6 |5 y4 R. z! J6 S, i5 U( B
9.CSS多色边框3 z# | R' n$ V: \5 C+ Y
CSS代码:
7 j( r* P; _& i#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 L/ Y6 u8 {+ R6 b
|