【问题标题】:Hide elements behind transparent DIV but not background隐藏透明 DIV 后面的元素但不隐藏背景
【发布时间】:2020-03-14 16:35:44
【问题描述】:

所以我圈出了 div(带有border-radius),每个都用一条线连接。问题是它们是半透明的,它们是从 div 的中心连接起来的,所以你可以看到一条穿过 div 的线。我可以使 div 不透明,但我不想显示背景。那么,有没有办法隐藏 div 后面的特定元素,但显示页面的背景?即使它使用的是 js/jquery。

这是我的模拟情况(在我的代码行中自动生成):

https://jsfiddle.net/muud6rqf/2/

body{
  background: url(http://www.intrawallpaper.com/static/images/abstract-mosaic-background.png) no-repeat center center fixed;
  background-size: cover;
}

.circle{
  border: 2px solid red;
  width: 36px;
  height: 36px;
  border-radius: 100%;
  position: absolute;
  box-shadow: 0 0 8px 2px rgba(255,0,0,0.6), inset 0 0 8px 2px rgba(255,0,0,0.6);
}

.simulated-line{
  position: absolute;
  width: 181px;
  height: 4px;
  background: green;
  top: 64px;
  left: 118px;
  transform-origin: 0% 50%;
  transform: rotate(25deg);
}
<div class="circle" style="left: 100px; top: 46px"></div>

<div class="circle" style="left: 260px; top: 121px"></div>
  
<div class="simulated-line"></div>

编辑:这就是它的样子:

这就是我想要的:

【问题讨论】:

  • 你能发布你的代码示例吗?
  • 您需要发布您的代码...在 sn-p 之前投反对票
  • 为什么不使用带有 css 圆圈的 div,而只使用 circle.png 作为该 div 的背景?
  • 好的,我会编辑对不起没有代码,但请不要投票他们会删除帖子:(
  • 嘿!你最近发布的小提琴很有趣。我建议您编辑您的问题以使其更准确。分段吧!解决问题......从概念的角度来看,您尝试做的事情看起来有点复杂。你想让我做什么 ?我赞成反对下跌;)

标签: javascript jquery html css


【解决方案1】:

z-index 有点小技巧,我不知道它是否适合你,但你可以看看 sn-p。

z-index:-1 添加到.simulated-line,这样线条就会回到圆圈。

background: inherit; 添加到.circle 以填充背景。

body{
  background: url(http://www.intrawallpaper.com/static/images/abstract-mosaic-background.png) no-repeat center center fixed;
  background-size: cover;
  background-color: #000;
}

.circle{
  border: 2px solid red;
  width: 36px;
  height: 36px;
  border-radius: 100%;
  position: absolute;
  box-shadow: 0 0 8px 2px rgba(255,0,0,0.6), inset 0 0 8px 2px rgba(255,0,0,0.6);
  background: inherit;
}

.simulated-line{
  position: absolute;
  width: 181px;
  height: 4px;
  background: green;
  top: 64px;
  left: 118px;
  transform-origin: 0% 50%;
  transform: rotate(25deg);
   z-index: -1;
}
<div class="circle" style="left: 100px; top: 46px"></div>

<div class="circle" style="left: 260px; top: 121px"></div>
  
<div class="simulated-line"></div>

【讨论】:

  • jsfiddle.net/muud6rqf/3 拖动圆圈,我更改了代码,现在画布是圆圈的兄弟
  • background:inherit 添加到.circle 类。见https://jsfiddle.net/muud6rqf/4/
  • 你知道当代码在演示小提琴中运行但在你的项目中运行时的感觉吗? :( 我会检查我的代码,但这是正确的答案,谢谢!
  • 我知道马恩的感觉 :) 欢迎
  • jsfiddle 对我不起作用,并显示圆圈内的线条(Chrome 和 Firefox)。这仍然应该工作吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-07
  • 1970-01-01
  • 1970-01-01
  • 2021-11-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多