我们假定我们的 HTML 构造以下:
<div></div>
法一、CSS3 扭转缩放
这里我们运用 伪元素 画出一条直线,然后绕 div 中间扭转 45度 ,再缩放一下就能够获得。
细致完成css代码:
div{ position:relative; margin:50px auto; width:100px; height:100px; box-sizing:border-box; border:1px solid #333; // background-color:#333; line-height:120px; text-indent:5px; } div::before{ content:""; position:absolute; left:0; top:0; width:100%; height:50px; box-sizing:border-box; border-bottom:1px solid deeppink; transform-origin:bottom center; // transform:rotateZ(45deg) scale(1.414); animation:slash 5s infinite ease; } @keyframes slash{ 0%{ transform:rotateZ(0deg) scale(1); } 30%{ transform:rotateZ(45deg) scale(1); } 60%{ transform:rotateZ(45deg) scale(1.414); } 100%{ transform:rotateZ(45deg) scale(1.414); } }
法二、线性渐变完成
这类要领运用了背景的线性渐变完成,渐变背景很主要的一点是,虽然名字唤作渐变,然则也是能够画出实色而非渐变色。
我们选定线性渐变的方向为 45deg,顺次将渐变色值设为:transparent -> deeppink -> deeppink ->transparent。
transparent 为通明色值。
就像如许简朴的一句,即可完成斜线结果:
div{ background: linear-gradient(45deg, transparent 49.5%, deeppink 49.5%, deeppink 50.5%, transparent 50.5%); }
以上就是css怎样绘制斜线的细致内容,更多请关注ki4网别的相干文章!