CSS position: relative 会导致 DOM 里排在前面位置的元素无法被碰撞测试? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
geelaw

CSS position: relative 会导致 DOM 里排在前面位置的元素无法被碰撞测试?

  •  
  •   geelaw May 28, 2017 2335 views
    This topic created in 3256 days ago, the information mentioned may be changed or developed.

    JSFiddle 在 这里

    你会发现第一个 div.test > a 是可以点击的,第二个不能( Microsoft Edge ),区别在于第二个 div.test > a 后面的 div.test > div#relative 具有 position: relative,即使设置了相反的 z-order 也不能。

    很诡异的现象,有人知道为啥么?标准怎么规定的?


    我是在设置我的 blog 的样式表的时候发现的这个问题。我本来是用 ::before 来显示那个“大号的引号”的,然后对 ::before 设置背景,再加上 position 放置位置。这是因为一开始我是成对显示引号的,还会有一个 ::after 用来显示另一个引号。因为 blockquote 具有 position: relative,导致右边 float: right 的链接点不到,于是用户将无法显示全部歌词。

    现在不这样做了,我直接用 blockquotebackground 显示那个“大号引号”。

    6 replies    2017-05-28 10:24:40 +08:00
    nlysh007
        1
    nlysh007  
       May 28, 2017
    css 里不应该是 z-index 么
    geelaw
        2
    geelaw  
    OP
       May 28, 2017
    @nlysh007 感谢提醒,这里是新的 JSFiddle: https://jsfiddle.net/augkvwb2/

    不过这并不影响问题,改成 z-index 仍然是无法点击的状态。
    nlysh007
        3
    nlysh007  
       May 28, 2017
    @geelaw
    #relative
    {
    position: relative;
    zindex:-1;
    }

    relative 好像是后来居上的。。。
    nlysh007
        4
    nlysh007  
       May 28, 2017
    @nlysh007
    写错了
    #relative
    {
    position: relative;
    z-index:-1;
    }
    P233
        5
    P233  
       May 28, 2017   1
    `div.test > a` 默认 `position: static`,`z-index` 无效,加上 `position: relative` 就可以了
    geelaw
        6
    geelaw  
    OP
       May 28, 2017 via Android
    @nlysh007 原因是 relative 之后建立了新的 stacking context ……

    @P233 谢谢您提供的原因
    About     Help     Advertise     Blog     API     FAQ     Solana     1478 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 29ms UTC 17:05 PVG 01:05 LAX 10:05 JFK 13:05
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86