html - :target does not work on my site

标签 html css

我找到了很酷的 CSS 来创建灯箱。它使用 :target 来显示灯箱 div。我在代码笔中尝试过,它工作正常,但在我的网站上它没有显示任何内容。我在我的代码中找不到其他阻止它显示的内容。这是基本代码:

HTML:

<a href="#img2" class="image">
    <img src="https://d2d00szk9na1qq.cloudfront.net/Product/2c6b113d-e972-42cc-a2de-f5dcf1c82e95/Images/Large_0297791.jpg">
  </a>

  <a href="#_" class="lightbox" id="img2">
    <img src="https://d2d00szk9na1qq.cloudfront.net/Product/2c6b113d-e972-42cc-a2de-f5dcf1c82e95/Images/Large_0297791.jpg">
  </a>` 

CSS:

.lightbox {
display: none;


position: fixed;
z-index: 999;
width: 100%;
height: 100%;
text-align: center;
top: 0;
left: 0;
background: rgba(0,0,0,0.8)
}
.lightbox img {
max-width: 90%;
max-height: 80%;
margin-top: 2%;
}

.lightbox:target {
outline: none;
display: block;
}

(代码笔:http://codepen.io/anon/pen/jrBrmp)

这是我的网站:http://test.fulfeal.co.uk/how-to/提前致谢。

亚历山大

最佳答案

您的站点安装中的某些东西阻止了 URL 在点击主题标签链接时发生变化。 :target 选择器作用于 URL 中的主题标签。

您将看到是否直接导航到 http://test.fulfeal.co.uk/how-to/#img1图像按预期弹出。所以您的 CSS 没有问题,问题出在您网站上的 URL 路由上。

在 codepen 中,URL 没有变化,因为底部的演示框有自己的 iframe,并且正在使用链接进行更新。

关于html - :target does not work on my site,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38064903/

相关文章:

html - 行高似乎不尊重 Chrome 上大字体的 Div

javascript - bootstrap form-inline 无法使用 d3 正确渲染

javascript - 如何避免使用溢出

javascript - 隐藏的嵌套导航在悬停之前显示

javascript - 集中统一调用函数的解决方案/想法

javascript - 按 viewBox 值移动事件 SVG

php - 通过 PHP 在 Wordpress 站点中动态包含 CSS

jquery - 导航栏切换在 ASP.Net 中的母版页上不起作用

html - Bootstrap 4 : center inline form inside a jumbotron

css - 考虑到文本节点,第一个 child 是否有 CSS 选择器?