阻止页面跳转:目标选择器

jic*_*ick 9 css

所以我使用CSS:target选择器弹出这个模态.但是,单击时页面会跳转到锚点.我想阻止页面跳转到:目标选择器.我怎样才能做到这一点?

<a href="#openModal">Info</a>

<div id="openModal" class="modalDialog">
Run Code Online (Sandbox Code Playgroud)

CSS:

.modalDialog {
    position: absolute;
    pointer-events: none;
    z-index: 99999;
opacity:0;
}

.modalDialog:target {
    opacity:1;
    pointer-events: auto;
}

.modalDialog > div {
    width: 900px;
    height: 506px;
    position: relative;
    background: rgba(0,0,0,0.9);
}
Run Code Online (Sandbox Code Playgroud)

Ser*_*gio 3

使用

<a href="#/">...</a> 
Run Code Online (Sandbox Code Playgroud)

为了改变 CSS 中的 :target 选择器但无处可去。片段 #/ 不存在,因此页面不会滚动,但 :target 选择器将发生变化以影响 CSS 更改。