css - IE11 : Add extra space above anchor tags

标签 css internet-explorer-11

我阅读了很多关于如何在 anchor 标记上方添加额外空间的建议,但没有一个在 IE11 中有效。

我需要在它们上方留出 250 像素的空间,因为我的粘性页眉大约有 250 像素高。

我尝试了两种最有前途的方法,一种使用 target 元素,第二种使用 id 元素:

/* target-Method: Working in Chrome, but not working in IE 11 */

:target::before {
  content:"";
  display:inline-block;
  height:250px; 
  margin:-250px 0 0 0; 
} 
/* id+before - Method: Working in Chrome, but not working in IE 11 */

h2[id], h3[id] { 
    position: relative;
    z-index: 1;
}
h2[id]::before, h3[id]::before { 
  display: inline-block !important; 
  content: ' ' !important;
  height: 250px !important;
  margin-top: -250px !important;
  visibility: hidden !important;
  pointer-events: none !important;
  position: absolute; 
  z-index: -1; 
}

但它们都不能在 IE11 中运行。

或者重叠元素上面的链接!

Codepen(这里没有粘性标题): https://codepen.io/abc001/pen/oRmmwp

最佳答案

尝试将以下代码与您的 Html 元素一起使用:

<style>
    /* target-Method: Working in Chrome, but not working in IE 11 */
    :target::before {
        content: "" !important;
        display: inline-block !important;
        background-color: antiquewhite !important;
        height: 250px !important;
        width: 100% !important;
        margin-top:250px;
    }

    /* id+before - Method: Working in Chrome, but not working in IE 11 */
    h2[id], h3[id] {
        position: relative;
        z-index: 1;
    }

        h2[id]::before, h3[id]::before {
            content: ' RR this -';
        }

    /* Spacer */
    .spacer {
        width: 100%;
        height: 500px;
    }

    .row .col-12{
        background-color:aquamarine
    }
</style>

结果如下:

enter image description here

关于css - IE11 : Add extra space above anchor tags,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56429818/

相关文章:

需要 CSS 样式帮助

html - 如何在 ie 11 中创建 css 双线直通?

html - 如何在 IE11 打印预览时避免分页?

javascript - SVG 中的字体图标在 IE 11 中不起作用

html - 修复了 Twitter bootstrap 3.2.0 中可滚动的布局高度

javascript - React-bootstrap 样式在完成 api 调用之前显示

javascript - 为什么此代码在 IE11、Chrome、Firefox 中不起作用,但在 IE8 中起作用?

css - Bootstrap glyphicon 出现但 IE11 抛出 CSS3111 错误

html - 尝试在 IE8 中使用不透明度

css - 没有固定宽度的div绕过固定宽度的父级