CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
5 v3 |/ m6 M! b. E& \0 X 以下各特效用的HTML代码相同:
% t0 @- g) Q1 l% Y% j+ {0 L<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
& F; b8 ~! N7 p. G1. CSS动画边框
& A1 d6 q1 i( D. YCSS代码:& q( ~8 [) g0 ]
@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;
} 效果如下:
* h4 g' k8 z$ e9 z) Y- P5 c
6 ]: a3 z1 Q2 R+ O( K
) n, H$ }4 F3 E6 {* ~
2. CSS图像边框7 ~8 L& `9 _( e; \9 Z; [$ u
CSS代码:% z; r5 ~8 ?" _1 [& Y9 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;
} 效果如下:
' ~. E; f& [2 L4 h: c& \
" T# f G1 |0 T: ]
' R7 t( F) x% Y0 w0 y7 d* ?* d3.CSS蛇式边框+ n2 f. P& J# s& ~& {+ P5 `( r, i7 F
CSS代码:
4 \. b( `+ r' c6 X& F#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;
} 效果如下:7 Q# }" J- a) x) ~
& C) Y( r" J: {5 }* K, L) ]9 N
3 v4 j/ q& A) i9 H, N4.CSS阶梯样式边框( w+ z4 P8 {: m v
CSS代码:+ S: Y& S: A. R! J
#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
} 效果如下:; S! m0 o+ [7 U5 J
! O7 A6 X* U$ w+ C
S/ `5 T. r) q2 a; E' e, C0 U( _5.CSS只有阴影边框" u1 \/ Y" P) c# @
CSS代码:. z7 D9 f2 I% 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;
} 效果如下:5 d/ C, C6 O/ R
" q& M! \) M# t3 G$ ?- Q# k4 Q
8 E5 X% N/ R: b
6.CSS带阴影和轮廓的边框
- x$ G. E: r" u: SCSS代码:! H+ w8 C% D( F5 U
#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;
} 效果如下:4 ] V1 X7 @' U
; a- q2 f/ i R' j& A" a) s8 u& @9 [$ x2 K
7.CSS少量阴影和轮廓的边框5 S0 y6 i. M* o" b4 W
CSS代码:4 h1 l$ J1 ~6 \/ W+ J
#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;
} 效果如下:1 H# M3 G4 f9 s/ K
2 ~6 O, q1 v3 M5 @$ \
6 u+ Z; l. h* t8 k) q9 m% m8.CSS带有阴影的双边框
5 I/ Z8 y4 f' Z+ S& v# O$ q) dCSS代码:! g, ~' q* B4 d! V H0 ^
#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;
} 效果如下:
/ i( ^9 a7 Q5 P' _+ `1 A8 L
) k! l, b: \/ D$ W8 _1 f/ o0 F/ H
( ?% ? N, O4 s# {- E5 K
9.CSS多色边框
6 p' g% H: d/ W' Q$ T' CCSS代码:
# [, ~: a2 | D#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;
} 效果如下:
# ]& `' q: r: a/ j# z6 U
|