CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
0 v9 f8 ^ C% q; V9 k( N( } 以下各特效用的HTML代码相同:
7 Q4 _7 W0 H* h& e; _<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
6 u; {" Z! \- o1. CSS动画边框
: A% n d& {6 L3 v/ j/ iCSS代码:
/ ~# j' G, K7 @) s; T; M@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;
} 效果如下:- a2 R: Z( z3 \
% J8 M0 }, F" ?( Z( g
) D+ b7 @4 z8 }
2. CSS图像边框5 \4 e% @' a0 g& o( Z q0 {
CSS代码:7 @4 i% q4 A9 S2 c: T3 r1 l% p- ]
#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;
} 效果如下:
1 l( T* d2 O4 ?
8 i, k! S& v- H- [
3 P8 e: x c/ Q% _! h
3.CSS蛇式边框, h, N) D4 m3 [' R4 z
CSS代码:% D0 p( I U( w+ e1 }" e Y7 T
#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 j/ k& S" P) p4 S
. N& D" H3 Z. C9 e: g
& B. ?2 o4 X2 x4.CSS阶梯样式边框$ ^0 w& i: e& s% x! X& v2 [- s
CSS代码:
/ G1 j# z2 E) o6 D; Y2 H#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
} 效果如下:
" p8 O+ c9 z& u$ }* q! l2 U% t
: S+ H& a0 ]. y
N2 @4 v& @- O* a$ J
5.CSS只有阴影边框
4 X# v/ N( A* A2 A$ D/ ~% b" _CSS代码:
" X1 w: |2 R s$ R#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
- B% {& {- M4 E% d- l% K( p
. g$ C7 s6 x3 r% j
* r1 i6 A- ]! @: D2 Y5 C6.CSS带阴影和轮廓的边框, I/ p# K+ L* p0 V3 j
CSS代码:
" g, b* Q% v6 d2 \#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;
} 效果如下:
9 D) B- c4 C# K: F S
( w$ R9 m! l" V3 t+ y( \1 a; e
/ `0 |7 X) }5 p. P- [
7.CSS少量阴影和轮廓的边框
7 e8 N" i0 ]* ]7 zCSS代码:
7 G! I) r, k; k3 p. L* P#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;
} 效果如下:8 ]) m; a& I) W
. W, r) Q8 c! r
4 n$ `! P$ X( D1 P) V& E
8.CSS带有阴影的双边框
( L( H% {0 B }5 G- P8 C6 MCSS代码:
# `+ U6 ~ n* W) H4 B2 t$ d4 X+ 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;
} 效果如下:4 a% P. a% ?2 g# y' B8 m" t" P
% m" v: l t/ F# T4 T* o6 W/ {
' w* U& e9 d7 g9.CSS多色边框$ w! E* B6 S) H! A( Z: S
CSS代码:
% S9 S/ k S1 H. l#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;
} 效果如下:9 Z/ L: | H6 v$ ^& k% l
|