如何用 CSS (或 SVG)倾斜地绘制两条线?
How can I draw two lines obliquely with CSS (or SVG)?
我想用 CSS(或 SVG)创建附加的 div 元素的背景图像。
div.target {
background-image: linear-gradient(
to right bottom,
transparent 50%,
#00BCD4 50%
);
我想用 CSS(或 SVG)创建的 div 元素的背景图片
我们可以像下面的代码片段一样使用多个背景图像渐变来做到这一点。较暗的阴影被指定为元素的背景颜色。然后放置两个使用渐变创建的背景图像层,以产生所需的效果。在较暗的阴影上方添加部分透明的白色层将产生较浅的阴影。
第二层的background-size
应该更小,它的background-position
应该在元素的左下角。
div {
height: 200px;
background-color: rgb(20,203,194);
background-image: linear-gradient(to top left, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) 50%), linear-gradient(to top right, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) 50%);
background-size: 100% 100%, 50px 50px;
background-position: left top, left bottom;
background-repeat: no-repeat;
}
<div></div>
有角度的 CSS 渐变已知会产生轻微的锯齿状(或不均匀或粗糙)边缘,可以通过像下面的演示那样偏移颜色停止点来避免这种情况。
div {
height: 200px;
background-color: rgb(20,203,194);
background-image: linear-gradient(to top left, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) calc(50% + 1px)), linear-gradient(to top right, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) calc(50% + 1px));
background-size: 100% 100%, 50px 50px;
background-position: left top, left bottom;
background-repeat: no-repeat;
}
<div></div>
您可以使用 :before
和 :after
伪元素来做到这一点。
div {
position: relative;
width: 500px;
height: 100px;
background: #0BC7BE;
}
div:after {
position: absolute;
border-style: solid;
border-width: 0 0 100px 500px;
border-color: transparent transparent rgba(255, 255, 255, 0.3) transparent;
right: 0;
top: 0;
content: "";
}
div:before {
position: absolute;
border-style: solid;
border-width: 50px 0 0 70px;
border-color: transparent transparent transparent rgba(255, 255, 255, 0.3);
left: 0;
bottom: 0;
content: "";
}
<div></div>
我想用 CSS(或 SVG)创建附加的 div 元素的背景图像。
div.target {
background-image: linear-gradient(
to right bottom,
transparent 50%,
#00BCD4 50%
);
我想用 CSS(或 SVG)创建的 div 元素的背景图片
我们可以像下面的代码片段一样使用多个背景图像渐变来做到这一点。较暗的阴影被指定为元素的背景颜色。然后放置两个使用渐变创建的背景图像层,以产生所需的效果。在较暗的阴影上方添加部分透明的白色层将产生较浅的阴影。
第二层的background-size
应该更小,它的background-position
应该在元素的左下角。
div {
height: 200px;
background-color: rgb(20,203,194);
background-image: linear-gradient(to top left, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) 50%), linear-gradient(to top right, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) 50%);
background-size: 100% 100%, 50px 50px;
background-position: left top, left bottom;
background-repeat: no-repeat;
}
<div></div>
有角度的 CSS 渐变已知会产生轻微的锯齿状(或不均匀或粗糙)边缘,可以通过像下面的演示那样偏移颜色停止点来避免这种情况。
div {
height: 200px;
background-color: rgb(20,203,194);
background-image: linear-gradient(to top left, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) calc(50% + 1px)), linear-gradient(to top right, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) calc(50% + 1px));
background-size: 100% 100%, 50px 50px;
background-position: left top, left bottom;
background-repeat: no-repeat;
}
<div></div>
您可以使用 :before
和 :after
伪元素来做到这一点。
div {
position: relative;
width: 500px;
height: 100px;
background: #0BC7BE;
}
div:after {
position: absolute;
border-style: solid;
border-width: 0 0 100px 500px;
border-color: transparent transparent rgba(255, 255, 255, 0.3) transparent;
right: 0;
top: 0;
content: "";
}
div:before {
position: absolute;
border-style: solid;
border-width: 50px 0 0 70px;
border-color: transparent transparent transparent rgba(255, 255, 255, 0.3);
left: 0;
bottom: 0;
content: "";
}
<div></div>