html - 边界半径不考虑 z-index

标签 html css

我有一个标题标签被相邻的 div 覆盖了。我已经为它们设置了 z-index 属性,但它们并没有像我希望的那样工作。我注意到当我将 border-radius 属性与其他杂项一起使用时会发生这种情况。 css 使两个 DOM 元素的对齐方式相互交叉。但是,他们以错误的顺序穿越我需要的东西。有什么想法吗?

Fiddle :)

h2 {
    font-size: 2.5em;
    background-color: #e5dbc2;
    display: inline-block;
    padding-right: 10px;
    line-height: 70%;
    margin-bottom: 0;
    z-index:999;
}


.cover {
    position:relative;
    width: 100%;
    height: 300px;
    padding: 0;
    border-radius: 0 0 20px 20px;
    background-color: #efe8d9;
    border-top: 5px solid #6e537f;
    margin-top: -7px;
    overflow: hidden;
    z-index: 500;
}

最佳答案

您忘记定位标题 - 添加 position: relative;<h2>

http://jsfiddle.net/Ms7Qr/1/ (z-index 不适用于静态定位的元素)

来自Visual Formatting Model :

Other stacking contexts are generated by any positioned element (including relatively positioned elements) having a computed value of 'z-index' other than 'auto'.

关于html - 边界半径不考虑 z-index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17069664/

相关文章:

javascript - 将html内容添加到js生成的类中

eclipse - Eclipse 中是否有任何方法可以像 Netbeans 那样格式化包含 div 的代码?

javascript - 所有视口(viewport)周围的进度条?

html - 一行中的三个 div,水平居中的另一列中的最后一个 - Flexbox 或 Grid

html - 我想通过 firebase 提供用户身份验证,但登录页面接受无效输入

javascript - 如何在显示/隐藏按钮上的文本旁边显示图标?

android - 使用 4.1 HTML 5 直播到 android

javascript - 在拖动之前更改元素 href

CSS PIE - 边界问题?

html - td 宽度百分比无法通过传递 html 注释客户端