使用 DIV 标签绘制竖线和横线并指定坐标位置
要使用 DIV 标签画一根竖线和一根横线,并指定它们的坐标位置,可以使用 CSS 的 position 属性和 top、left 属性来实现。
HTML 代码:
<div class='line vertical'></div>
<div class='line horizontal'></div>
CSS 代码:
.line {
position: absolute;
background-color: black;
}
.vertical {
width: 1px;
height: 100px; /* 竖线高度 */
top: 50px; /* 竖线的垂直位置 */
left: 100px; /* 竖线的水平位置 */
}
.horizontal {
width: 100px; /* 横线宽度 */
height: 1px;
top: 150px; /* 横线的垂直位置 */
left: 50px; /* 横线的水平位置 */
}
在上述代码中,我们使用了两个 DIV 元素,分别设置了 class 为 'line vertical' 和 'line horizontal'。CSS 中,我们使用 position: absolute; 将这两个 DIV 的定位方式设置为绝对定位,这样才能使用 top 和 left 属性来指定它们的位置。
对于竖线,我们设置了 width 为 1px,height 为 100px 来确定它的尺寸,top 为 50px,left 为 100px 来确定它的位置。
对于横线,我们设置了 width 为 100px,height 为 1px 来确定它的尺寸,top 为 150px,left 为 50px 来确定它的位置。
这样就可以在指定的坐标位置上画出一根竖线和一根横线。
原文地址: https://www.cveoy.top/t/topic/dUfZ 著作权归作者所有。请勿转载和采集!