CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
8 A, e* M/ @" J7 S$ I( }! i 以下各特效用的HTML代码相同:
# r1 P/ i: x' [* K( x<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 0 W/ T: J! b' E. ~( L$ ]
1. CSS动画边框# o" w. ^7 p3 R) \( [5 p" f
CSS代码:" Q3 ~) H8 U0 B+ h, p% O, A4 E, T# o
@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 M% C8 ]1 t, P* U
4 |0 ^6 e, \% a |+ t* z" ` u5 t& K! F9 \) G
2. CSS图像边框+ K, ]& s& l9 U; S( D4 l \& A6 \3 o
CSS代码:! z, D3 x* t0 n# W: f
#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;
} 效果如下:$ ~/ K% H+ {" T! e1 \$ q
, o8 r5 O! B5 I
" {$ ^" E7 I/ k6 C( g3.CSS蛇式边框" p- ]$ g3 B+ f" j- e# O
CSS代码:
% q/ R% o! M2 M* ?* T+ 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;
} 效果如下:0 M* H! u% R# z* ?' e2 h, o; e" A
: A, _# O& N( W: b8 [3 Z# }- L1 K6 @+ w: Z# u
4.CSS阶梯样式边框
4 w2 g) B5 Q# Q" X. M/ zCSS代码:6 M# {7 l* K2 Q! T, ?, e9 R+ I
#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
} 效果如下:
, M. @8 c( h2 t, `( S$ m
5 J X. r8 L4 P* h/ O6 ~2 X
5 V# b. {+ Q% K) B; I5.CSS只有阴影边框 K$ I. e2 L4 K3 {* M2 a/ l
CSS代码:
- P( H |- N/ _! e9 g( c" A7 {#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
0 ]. M. a; v) Y
9 c$ `% z& r6 H* |$ B( }, X& d3 ]! U/ h. c
6.CSS带阴影和轮廓的边框
2 {% ]3 \8 L; I% Z% B- {$ I& {CSS代码:/ ~% Z- v- D" D) a) ^
#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;
} 效果如下:& w) `- @4 g$ S! w) U5 U4 O
v6 n+ }* U- M7 M8 p0 c' R5 G, w1 h; E: {
7.CSS少量阴影和轮廓的边框8 ^* U9 d+ a9 R$ d
CSS代码:
* L$ d3 P6 B+ x& J' c' z#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;
} 效果如下:
' g- t+ i& `! y% x, x# l
( }; w% [' C0 {, Y( ^6 \! L- T1 |
8.CSS带有阴影的双边框
3 \, v; z) U$ K" E! yCSS代码:
) o. |9 f/ @( Y) M#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;
} 效果如下:5 j( e- b8 M' e. y% \
* f; D9 P+ b6 ^
) c( g+ G$ M4 r2 O
9.CSS多色边框
3 e# v* w3 @" n2 ^CSS代码:& l1 [8 n( R# G; ~; o
#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;
} 效果如下:1 r7 t' r* M: U- a
|