简体   繁体   English

在可点击链接上方划分

[英]Div above a clickable link

I want to make a div above an another div which contains a link. 我想在另一个包含链接的div之上创建一个div。 The problem is that the first div prevents to access on the link. 问题是第一个div阻止访问链接。 It's possible to make it present but accessible ? 有可能使其呈现但可访问吗?

(I don't want to make a border around a div, or something like that, i really want to make div above an other div) (我不想在div周围做边框,或类似的东西,我真的想使div在另一个div之上)

DEMO IN FIDDLE 在演示中

HTML : HTML:

<div class="top">
<a href="#">LINK</a>
</div>
<div class="bottom"></div>

CSS : CSS:

.top { 
height:100px;
width:200px;
position:fixed;
top:10px;
background:yellow; }

.bottom { 
height:50px;
position:fixed;
top:10px;
width:100px;
border:3px solid red; }

I believe you are looking for pointer-events:none; 我相信您正在寻找pointer-events:none; in the CSS of .bottom 在.bottom的CSS中

Try this: 尝试这个:

.bottom { 
    height:50px;
    position:fixed;
    top:10px;
    width:100px;
    border:3px solid red;
    pointer-events:none;
}

http://jsfiddle.net/wrxsti85/aYV4J/ http://jsfiddle.net/wrxsti85/aYV4J/

Hope it helps! 希望能帮助到你!

Edit: Added a fiddle 编辑:添加了一个小提琴

you can do this by this way 你可以这样

.top a{
    position:relative;
    z-index:2;
}

and in .bottom div mention .bottom div中提到

.bottom { 
    z-index:1;
}

updated jsFiddle file 更新了jsFiddle文件

use z-index 使用z-index

demo 演示

.top {
    height:100px;
    width:200px;
    position:fixed;
    top:10px;
    background:yellow;
    z-index:99999;
}
.bottom {
    height:50px;
    position:fixed;
    top:10px;
    width:100px;
    border:3px solid red;
}

Use z-index to place one over the other: 使用z-index将一个放置在另一个上方:

.top {
    height:100px;
    width:200px;
    position:fixed;
    top:10px;
    z-index:1;
    background:yellow;
}
.bottom {
    height:50px;
    position:fixed;
    top:10px;
    width:100px;
    border:3px solid red;
    z-index:0;
}

Just add with your current CSS: 只需添加您当前的CSS:

.bottom{
    ....

    pointer-events:none;
}

Otherwise, you can add/increase a z-Index value for the .top class only if you don't have any z-Index limitation in your case. 否则,只有在没有任何z-Index限制的情况下,才可以为.top类添加/增加z-Index值。

I do not get why you guys are using position:fixed here. 我不明白你们为什么使用position:fixed在这里。 If you don't want any borders and want it to be simple then use : 如果您不希望有任何边界并且希望它简单易用,请使用:

.top { 
    height:100px;
    width:200px;
    background:yellow; 
    position:relative;
}

.bottom { 
    height:50px;
    position:absolute;
    top:10px;
    width:100px;
    border:3px solid red; 
    z-index:-1;
  }

Link to fiddle http://jsfiddle.net/wVLa8/24/ 链接到小提琴http://jsfiddle.net/wVLa8/24/

Please check this fiddle . 请检查这个小提琴 Maybe holding the right ear with left hand but the only solution (without browser support problem) to create invisible mirror objects front of the object which makes behind objects inaccessible and let them transfer events to original objects... 也许用左手握住右耳,但是唯一的解决方案(没有浏览器支持问题)可以在对象的前面创建不可见的镜像对象,从而使后面的对象无法访问并将事件转移到原始对象...

$(function () {

    $.each($('.back').children(), function () {

        var $behindObject = $(this),
            $behindObjectOffset = $behindObject.position();

        $('<div class="invisible-mirrors">')
            .css({
                width: $behindObject.width(),
                height: $behindObject.height(),
                top: $behindObjectOffset.top,
                left: $behindObjectOffset.left
            })
            .on('click', function () {
                $behindObject.trigger("click");
            })
            .appendTo('.fore')
    });


    //test of click event

    $('.back a').on('click', function () {
        $(this).text($(this).text() + ' got the event : click')
    })


})

Holy crap none of this is necessary. 天哪,这都是没有必要的。 Do not use Z-INDEX and do not use POINTER-EVENTS. 不要使用Z-INDEX,也不要使用POINTER-EVENTS。

Please look at this Fiddle first 请先看这个小提琴

Just re-arrange your HTML and name your CSS selectors correctly: 只需重新排列HTML并正确命名CSS选择器即可:

HTML: HTML:

<div class="bottom">
    <div class="top"> <a href="#">LINK</a>
    </div>
</div>

Elements considered "UNDER" or "BEFORE" other elements appear first in HTML. 被认为“其他”或“之前”的元素在HTML中首先出现。

CSS: CSS:

.bottom {
    height:100px;
    width:200px;
    position:fixed;
    top:10px;
    background:yellow;
}
.top {
    height:50px;
    position:absolute;
    width:100px;
    border:3px solid red;
}

You also don't need them both position: fixed; 您也不需要两个position: fixed; . Only the container. 只有容器。 This also means they shouldn't be one, then the other. 这也意味着他们不应该是一个,然后是另一个。 If you really need them like that, you can keep them both fixed as before and change the HTML but I would advise against that. 如果真的需要它们,可以像以前一样固定它们并更改HTML,但我建议不要这样做。

Try this, it puts the Divs on top of each other: 试试这个,它将Divs放在另一个之上:

.top { 
    height:100px;
    width:200px;
    top:10px;
    background:yellow;
    display:block;}

.bottom { 
    height:50px;
    top:10px;
    width:100px;
    border:3px solid red;
    display:block;}

Not sure why youve done it the way you have. 不知道为什么要按照自己的方式做。

Z-index can be used to put one div above another however there are better ways to do what you want. Z-index可用于将一个div放在另一个div之上,但是有更好的方法来做您想要的事情。

See this Fiddle 看到这个小提琴

HTML HTML

<div class="bottom">
<a href="#">LINK</a>
</div>

css CSS

 .bottom {height:auto;width:100px;border:3px solid red;background:yellow; }
 .bottom a {display:block;margin:0 auto;background:yellow;padding:20px;text-align:center;}

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

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