CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。4 q' K- I) f0 \ h
以下各特效用的HTML代码相同:& H6 ?' \% _6 I' F& X" W$ u- d
- <div id="box">
- 编程适合那些有不同想法的人... <br/>
- 对于那些想要创造大事物并愿意改变世界的人们。
- </div>
+ Z' h/ ~; Y& K% ?& O# @3 J
1. CSS动画边框/ O; B! @/ A; b% Y- ?$ v8 E
CSS代码:; s1 b2 r( ^( u! x, c- ^" c6 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;
- }
效果如下:
3 K7 w+ ], ^2 Z
1 Y2 O- q! H3 U, j5 H3 S
7 Q5 @( _# W8 |2. CSS图像边框
3 b& G2 ~. L0 ^6 P8 [5 l& gCSS代码:5 p" T2 v2 O- i4 x
- #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;
- }
效果如下:8 N- Q1 i% h7 q2 X( [1 Q, U
" p* h4 ~# y& A% R+ v; L% v6 s4 X& D/ w. C# a
3.CSS蛇式边框
! V7 Y, {4 [5 wCSS代码:/ u: n a: v G, S& P
- #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;
- }
效果如下:
: V4 k5 y6 v P$ K, s, d
/ Q+ ] ?. b$ A6 ?6 V& j5 M
! K2 w5 ]! q# {& M, X
4.CSS阶梯样式边框1 F' d8 l( P; [7 a( ^! m
CSS代码:
6 K" H* N- v9 D4 V, P- #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
- }
效果如下:
% I7 E( X% V# C7 q6 N+ F
& D% L0 S$ K# T* v- }( J
* U: \ T# n. ^- i5.CSS只有阴影边框
4 x/ S9 C8 M9 d- NCSS代码:; x) ]( _- E% y6 J! R+ T
- #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' _, V* z2 q0 C. w
- p3 {7 y& c0 U
% H$ Y6 ~5 R8 i6.CSS带阴影和轮廓的边框2 {) C, l0 y3 i. z) ^$ v& Z) {
CSS代码:/ j% v1 }- o. U' ^. g1 i
- #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;
- }
效果如下:% j1 }% i- k# }0 z$ B8 a# p# U
' p) I- m: E! ~1 s. F, l
+ L: T* \) j& b7 h; R) J7.CSS少量阴影和轮廓的边框+ X) j/ c0 p* J/ T7 G
CSS代码:! M7 a: `* W0 h: ]& [
- #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;
- }
效果如下:
, I9 X7 k% B) S% _& ?: a: L
_2 `7 t+ ?1 P3 U# `3 A
, m" |$ }/ r0 |" |5 _8.CSS带有阴影的双边框- ^# q0 V W+ ]$ Y
CSS代码:
, p$ m* S( m3 |' x4 }5 Q- #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;
- }
效果如下:
. d3 l& Z! }! g! U
8 \" W7 Q% I' D. x" T3 G
6 ]6 @. h. e2 x: g) k- t' l9.CSS多色边框
: H9 s8 n0 g7 E* S6 x# F UCSS代码:
8 G$ L* U! t5 J, G- #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;
- }
效果如下:
& m, X5 R V1 r' R1 k6 t3 c
|