:target pseudo-class not working properly in firefox

一个人想着一个人 提交于 2019-12-12 04:19:43

问题


I am making a page with a CSS lightbox-type effect using the :target pseudo-class. When you click on an image, a box pops up with info in it, and goes away again when you click anywhere.

It's working perfectly in Chrome and IE, but in firefox there is a weird bug where the text in my lightbox div disappears when you move the mouse away from the box. It's acting like a hover effect, where you can only see the text when you are hovering over it.

I hope that explanation made sense, please let me know if I was not clear.

My CSS is here:

.lightbox {
display: none;
position: absolute;
z-index: 8;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: #fff; 
padding-left: 30px;
}

.lightbox:target {
/* Show lightbox when it is target */
display: block !important;
outline: none;
}

Let me know if you need more information.

Thank you very much!


回答1:


The pseudo-class target works on id elements, not classes: https://developer.mozilla.org/en-US/docs/Web/CSS/:target

The :target pseudo-class represents the unique element, if any, with an id matching the fragment identifier of the URI of the document.

Try replacing your .lightbox with #lightbox in your CSS, and your HTML element should be <div id="lightbox">

#lightbox {
    display: none;
    position: absolute;
    z-index: 8;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: #fff; 
    padding-left: 30px;
}

#lightbox:target {
    /* Show lightbox when it is target */
    display: block !important;
    outline: none;
}


来源:https://stackoverflow.com/questions/44616472/firefox-handling-css-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!