CSS边框效果
本文将详细介绍CSS边框效果
半透明边框
border:10px solid hsla(0, 0%, 100%,.5); background-clip:padding-box;
缝边效果
outline: 1px white dashed; outline-offset:-10px; border-radius:4%; background:#795548;
边框内圆角
思路如下:为元素设置圆角,外层设置轮廓outline。圆角与直角之间的空隙用阴影补齐,阴影的尺寸为圆角半径的一半
border-radius:10px; background: tan; outline:10px solid #655; box-shadow:0 0 0 5px #655;
信封边框
信封边框有两种实现思路:
1、使用背景渐变
padding:1em; border: 1em solid transparent; background: linear-gradient(white,white) padding-box,repeating-linear-gradient(-45deg, red 0, red 12.5%, transparent 0, transparent 25%, #58a 0, #58a 37.5%, transparent 0, transparent 50%) 0/5em 5em;
2、使用边框图片
padding:1em; border: 1em solid transparent; border-image:repeating-linear-gradient(-45deg, red 0, red 1em, transparent 0, transparent 2em, #58a 0, #58a 3em, transparent 0, transparent 4em) 16;
效果如下
脚注效果
由于使用了currentColor,它会根据color属性的变化而自动适应
padding-top:1em; border-top: .2em solid transparent; border-image: 100% 0 0 linear-gradient(90deg,currentColor 4em,transparent 0);
蚂蚁线
@keyframes ants{100%{background-position:100%;}} div{ width:200px; height: 70px; border: 1px solid transparent; background: linear-gradient(white,white) padding-box,repeating-linear-gradient(-45deg, black 0, black 25%, white 0, white 50%) 0/.6em .6em; animation:ants 12s linear infinite; }