CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。7 t( t" J9 h: W; a$ A& Z! z; D u
以下各特效用的HTML代码相同:
2 S7 i. D2 M: j<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
9 G3 g/ b9 q. v: q) g' r% u# L1. CSS动画边框
( r7 A& _" h# t: iCSS代码:
1 S1 Q' l4 {9 J1 a8 ?, k@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;
} 效果如下:' A0 b% s, W F" R* V! W/ L
/ x! ?" L8 d5 Q% y4 d" V- Z
" \* x7 H+ Q+ X: b
2. CSS图像边框2 W+ x/ y! k6 K8 T* B6 u$ F* \
CSS代码:0 S3 c O/ j) d+ n2 j
#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;
} 效果如下:) n: x4 a' L- |. J( r4 q
9 G; z& V$ z; O" q$ y! o
5 A7 G1 @, @5 O( u% y3.CSS蛇式边框' x0 z' [8 z4 e. v5 G; s" q
CSS代码:9 S+ t, C2 e9 M' ]4 t& w) t# }$ D
#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;
} 效果如下:
) q9 y0 ]& z. g+ C
4 @: T$ l. I6 k7 Q! Z; X( M1 ?3 U( Z& n# Z
4.CSS阶梯样式边框
" v6 Y" u4 }" c3 C$ u* P% V' ^CSS代码:
$ u2 ^4 H, x/ [# E# ~" D2 u% A+ D @#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
} 效果如下:& `; }7 p: c- ?- C0 K
3 W9 T# S8 U% c2 H, K9 m( j- L/ {) H, M& V) N4 h7 Z' z& L5 ~& z! N
5.CSS只有阴影边框
* ~) N4 n- p5 f P) yCSS代码:: D6 Y# r; o: o" F' E' e8 d0 x
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:4 l& _7 U$ Y$ ^& h4 p! ]( H2 l9 M
9 W6 k3 e" G' [) p- Z
2 c( N( b! w4 ]! p% p$ b6.CSS带阴影和轮廓的边框
* k, u% C2 v3 {. O9 h0 ]+ KCSS代码:; m# t6 U4 b; Z4 g1 K6 @
#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;
} 效果如下:# i3 Y$ b6 E+ E8 T, ~
, ]3 p, n, H a. U6 A* s
+ ?) B4 l2 z1 Z' @8 ?& n7 y: [ K* H
7.CSS少量阴影和轮廓的边框
* e' T7 B9 R* h, I& g: bCSS代码:3 T# g0 ~$ U/ C* ^
#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;
} 效果如下:0 E$ R4 |% D' B. G0 [2 b# n! |
0 t) b0 s, j& [9 s# N( g* U& I7 X; x" y+ {
8.CSS带有阴影的双边框$ o! U- I- \4 {" F, c! T1 A% ^
CSS代码:
/ j1 ]7 f- N7 ]: y3 H#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 ~2 o+ ^5 V! B, [2 e4 X
; _% l o. d9 V8 l4 G5 H
3 Q8 A5 u" I( y9.CSS多色边框5 c9 ]4 q! Y5 R7 r2 j
CSS代码:# P% w1 U9 x: v
#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;
} 效果如下:
% P4 i, m/ }- k+ ?2 a6 g+ N
|