简体   繁体   English

为什么我的 CSS styles 在使用:目标伪 class 时没有被应用?

[英]Why aren't my CSS styles being applied when using the :target pseudo class on Wordpress?

I have a codepen here: https://codepen.io/tylerjms7/pen/ZEEvRyV where I've used the:target pseudo class as a way of opening and closing a modal.我在这里有一个codepen: https://codepen.io/tylerjms7/pen/ZEEvRyV ,我使用了:target pseudo class 作为打开和关闭模态的方式。

The problem is when I take that exact same code and apply it to a Wordpress site here: https://goals.brandoncollins.org/test-target it doesn't work.问题是当我采用完全相同的代码并将其应用于 Wordpress 站点时: https://goals.brandoncollins.org/test-target它不起作用。

Basically the styles aren't being applied to the:target element for some reason.基本上 styles 由于某种原因没有应用于:target 元素。 But I can't figure out why.但我不知道为什么。 The thing that is weird is that if I open that link in a new tab with the #creategp at the end the style will work initially to open the modal.奇怪的是,如果我在一个新选项卡中打开该链接,最后带有#creategp,则样式最初将用于打开模式。 When I click the close icon it also works to remove the styles and hide the modal as expected.当我单击关闭图标时,它也可以删除 styles 并按预期隐藏模式。 But then clicking the modal again won't work just as before.但是然后再次单击模态将无法像以前那样工作。

So why aren't the styles being applied?那么为什么没有应用 styles 呢? Also, why are they being applied on a new tab?另外,为什么要在新标签上应用它们?

<a href="#creategp" class="ty-modal-launch">Open Modal</a>
<!-- The Modal -->
<div id="creategp">
    <div class="ty-modal">
        <a href="#close" title="Close" class="closeit">X</a>
        <p>Modal Content</p>
    </div>
</div>


#creategp:target {
    opacity: 1;
    visibility: visible;
    transition: opacity 1s, visibility 1s;
}


#creategp:target {
    opacity: 1;
    visibility: visible;
    transition: opacity 1s, visibility 1s;
}

When I run this in Codepen I get exactly what I want.当我在 Codepen 中运行它时,我得到了我想要的。 But when I add these same HTML and styles to my wordpress site it doesn't work unless I open it in a new tab.但是,当我将这些相同的 HTML 和 styles 添加到我的 wordpress 站点时,它不起作用,除非我在新选项卡中打开它。 And then it only works once.然后它只工作一次。

I had some debug with chrome tool and your CSS code didn't work because of this:我使用 chrome 工具进行了一些调试,因此您的 CSS 代码不起作用: 在此处输入图像描述

goals.brandoncollins.org/wp-content/themes/pro/framework/dist/js/site/x.js?ver=3.0.4目标.brandoncollins.org/wp-content/themes/pro/framework/dist/js/site/x.js?ver=3.0.4

When I block request for that js url:当我阻止对该 js url 的请求时: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM