CSS如何连接线

标签 css line

我必须在 <div> 中用 CSS 创建水平线元素,现在我想用另一条线(手工绘制的线)加入它们,有什么想法吗?下面是我正在做的事情的图片:

enter image description here

.canvas {
  top: 1px;
  left: 1px;
  background-color: #CCC;
  width: 1000px;
  height: 1000px;
}

.top-line {
  top: 100px;
  left: 256px;
  position: absolute;
  border-top: 1px solid #000;
  height: 1px;
  width: 488px;
}

.bottom-line {
  top: 900px;
  left: 100px;
  position: absolute;
  border-top: 1px solid #000;
  height: 1px;
  width: 800px;
}
<div class="canvas">
  <div class="top-line"></div>
  <div class="left-line"></div>
  <div class="right-line"></div>
  <div class="bottom-line"></div>
</div>

最佳答案

你可以考虑一个元素和一些转换来直观地实现你想要的:

.box {
  width:300px;
  height:200px;
  border:1px solid;
  border-right:none; /*remove this if you want the right line too*/
  transform:perspective(30px) rotateX(5deg);
  transform-origin:bottom center;
}

body {
  background:pink;
}
<div class="box">
</div>

另一种考虑倾斜变换的想法:

.box {
  width:300px;
  height:200px;
  border-bottom:1px solid;
  position:relative;
}
.box:before,
.box:after {
  content:"";
  position:absolute;
  top:0;
  height:100%;
  width:50%;
  border-top:1px solid;
}
.box:before {
  border-left:1px solid;
  transform-origin:bottom left;
  left:0;
  transform:skew(-10deg);
}
.box:after {
  /*border-right:1px solid; add this for the right line */
  transform-origin:bottom right;
  right:0;
  transform:skew(10deg);
}

body {
  background:pink;
}
<div class="box">
</div>

关于CSS如何连接线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55385928/

相关文章:

html - 什么是最不坏的 : Inline size from code-behind or using tables?

javascript - 如何缩小自定义Chartjs水平线的高度并增加线宽?

Python OpenCV 如何去除行与行之间的空格

c# - 无法将参数传递给控制台应用程序,我的想法是否存在缺陷?

c - 问 : Read line to line from file and send to child process with pipes

jquery - 带有 jQ​​uery Waypoints 的 Chrome 和 Opera 中复选框的非常奇怪的行为

javascript - 如何用文章覆盖 div,直到鼠标悬停显示 div

css - 如何使用CSS仅选择显示的元素

android - 如何在运行时在自定义 View 中画线?

algorithm - 有没有超快的算法可以在图片上找到线条?