划边线的几种思路

发布时间 2023-08-16 11:07:40作者: 看风景就

1. border

2. outline

outline 与border很像,但是outline支持偏移
outline 不占据空间,很牛B的特性,绘制于元素内容周围。
outline 通常是矩形,但也可以是非矩形的。

/* 颜色 | 样式 | 宽度 */
outline: green solid 3px;
/* 偏移 */
outline-offset: 10px;

3. background

background: linear-gradient(to right, #000000, #000000 5px, transparent 5px, transparent);

background-size 和 background-position可模拟位置,粗细,长短,颜色,渐变色等,但是不能实现删除线,因为是背景

4. text-decoration

可调整 样式,颜色,粗细,偏移(负值可实现删除线),位置

text-decoration-line: underline;
text-decoration-style: wavy;
text-decoration-color: red;
text-decoration-thickness: 0.1em;
text-underline-offset: -0.5em;
text-underline-position: under left;