html - 目标元素不响应

标签 html css

我正在尝试执行 left_warrper不可见,在用户点击“点击我” 按钮后,left_warrper变为可见,但 :target元素由于某种原因不工作

.left_wrapper {
  background: rgba(0,0,0,.7);
  cursor: default;
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  bottom: 0;
  visibility: hidden;
  -webkit-transition: opacity .5s, visibility 0s linear .5s;
  transition: opacity .5s, visibility 0s linear .5s;
}

:target .left_wrapper {
    opacity: 1;
    visibility: visible;
}
<a href="#sidebar" style="position:absolute;right:0px;z-index:1;">click me</a>
  <div id="sidebar" class="wrapper">
      <div class="slide">
      </div>
  </div>
<a href="#" class="left_wrapper"></a>

Young Kyun Jin 效果很好,但是当我将代码添加到主 .html 页面时,我做了一些更改,比如添加了 <nav>元素,现在它又不起作用了,我怎么能检测到它呢?

代码如下:

<nav id="menu">
<img src="Logo.png" style="position: fixed; width: 30%; top: 10px; left: 10px;">
    <a href="#sidebar"><img src="../img/menu.png" style="position: fixed; top: 22px; right: 10px;"></a>
      <div id="sidebar" class="wrapper">
          <div class="slide">
            <a class="close" href="#">&times;</a>
          </div>
      </div>
    </nav>
    <a href="#" class="left_wrapper"></a>

最佳答案

.left_wrapper {
  background: rgba(0,0,0,.7);
  cursor: default;
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  bottom: 0;
  visibility: hidden;
  -webkit-transition: opacity .5s, visibility 0s linear .5s;
  transition: opacity .5s, visibility 0s linear .5s;
}

:target ~ .left_wrapper {
    opacity: 1;
    visibility: visible;
}
<a href="#sidebar" style="position:absolute;right:0px;z-index:1;">click me</a>
  <div id="sidebar" class="wrapper">
      <div class="slide">
      </div>
  </div>
<a href="#" class="left_wrapper"></a>

:target ~ .left_wrapper

~是兄弟选择器

关于html - 目标元素不响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46227620/

相关文章:

html - 2 inc/dec 按钮的 css 通过在调整屏幕大小时正确重新定位的输入

javascript - 在 div 文本上垂直滚动

javascript - ng-if 初始动画不适用于自定义指令

javascript - 在视口(viewport)上对 SVG 元素进行动画处理

python - python 中 html 文件的 string.format() 问题

html - 使用 CSS 将按钮内容移动到 Bootstrap 选项卡的右上角

javascript - 单击附加导航栏

javascript - 如何淡入标题中的所有元素?

css - 使 CSS 仅在 IE 上工作而无需单独的 CSS 表的通用方法

javascript - 使用 Bootstrap 在弹出窗口中出现问题