javascript - 连接 2 个 div 的边框或虚线

标签 javascript html css

我在用虚线连接 2 个 div 时遇到问题,我尝试使用 ::after::before 执行此操作,但没有成功。您可以在以下位置查看我的结构:

JS fiddle code

以及我想要实现的目标的图像:

enter image description here

这可能吗?如果是,那么我应该在代码中添加或更改什么?

谢谢。

最诚挚的问候,

最佳答案

使用 :before/:after 和 border-radius 你可以实现这一点(严格使用 css)。我在下面举了一个例子。

https://jsfiddle.net/m3zoz34f/8/

.box-top-right{
  position: relative;
}
.box-top-right:after{
    content: ' ';
    border-bottom-right-radius: 175px;
    width: 106%;
    position: absolute;
    border-bottom: 2px solid red;
    right: 0;
    bottom: -175px;
    height: 185px;
    border-bottom-style: dashed
}

.box-bottom:before{
  content: ' ';
  width: 66%;
  border-top: 2px solid red;
  height: 135px;
  position: absolute;
  top: -125px;
  border-top-left-radius: 150px;
  border-top-style: dashed;
}

.box-top, .box-bottom{
  position:relative;
  width:100%;
  min-height:400px;
}

.box-top-left, .box-top-right, .box-bt-left, .box-bt-right{
  float:left;
}

.box-top-left, .box-bt-right{
  width:65%;
  background-color:red;
  color:white;
  min-height:190px;
  text-align:center;
  padding-top:10px;
}

.box-top-right, .box-bt-left{
  width:30%;
  border:2px solid black;
  margin-left:2%;
  min-height:90px;
  text-align:center;
  padding-top:10px;
}

.box-bt-left{
  margin-left:0;
  margin-right:2%;
}

.box-bt-right{
  background-color:gray;
}
<div class="box-top">
  <div class="box-top-left">
    This is top left box
  </div>
  <div class="box-top-right">
    This is top right box
  </div>
</div>
<div class="box-bottom">
  <div class="box-bt-left">
    This is bottom left box
  </div>
  <div class="box-bt-right">
  This is bottom right box
  </div>
</div>

关于javascript - 连接 2 个 div 的边框或虚线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34443667/

相关文章:

javascript - 单击时在 youtube iframe 下隐藏一个 div

javascript - 使用 "TypeError: $ is not a function"时我得到 "import * as jQuery"

javascript - Vuejs 提交突变失败

javascript - 如何在没有权限错误的情况下将变量从触发函数中取出并放入局部变量中

javascript - 仅替换 iframe 的编码字符 Jquery

javascript - 将数组与推送的输入值相加

jquery - 带有 slideDown 的下拉菜单,单击时更改菜单标题

html - CSS 背景边距顶部效果

javascript - HTML + CSS 渲染问题

javascript - 如何检查变量值是增加还是减少并显示增加或减少的数字