Jar*_*sto 13
您可以通过多种方式执行此操作.
1)背景图像
1.1)SVG
您可以创建一个svg direct作为内联代码并使用它来绘制线条.使用它你可以实现很好的效果,如阴影,渐变,虚线......等等.在css background-image元素中使用svg也是可行的.
<svg style='width: 100%; height: 100%;'>
<line x1="0" y1="100%" x2="100%" y2="0"
style="stroke:rgb(0,0,0);stroke-width:1"/>
</svg>
Run Code Online (Sandbox Code Playgroud)
1.2)修复图像(png,jpg,...)
您还可以使用简单图像作为完整div上的背景图像.
2)创建线性背景渐变
.testDiv {
width: 300px;
height: 300px;
background:linear-gradient(to bottom right, transparent calc(50% - 1px), black calc(50% - 1px), black 50%, transparent 50%);
}
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
(在这里阅读更多)
3)旋转内部div(仅在方形div上)
在调整testDiv的大小时,该线应保持对角线.
.testDiv{
width: 600px;
height: 600px;
background-color: gray;
}
.lineDiv {
position: relative;
top: 29%;
left: 29%;
width: 142%;
height: 142%;
border-left: solid thin blue;
transform: rotate(45deg);
}
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
- > 142 = sqrt(100 ^ 2 + 100 ^ 2)(参见phytagoras)