【问题标题】:Positioning the fixed positioned elements child elements on top of each other将固定定位元素的子元素相互叠加
【发布时间】:2013-09-05 03:50:25
【问题描述】:

我的代码是这样的

<div class="nav-fixed">
    <div class="brand">
        Logo of the company
    </div>
    <div class="menu">
        <ul>
            <li>Home</li>
            <li>About</li>
            <li>Products</li>
            <li>Others</li>
        </ul>
    </div>

</div>

<div class="data">
    <p>
    If the element has 'position: absolute', the containing block is established by the nearest ancestor with a 'position' of 'absolute', 'relative' or 'fixed' ...
    </p>    
</div>

<div class="overlay">

</div>

 <div class="highlight">

 </div>

在此我有 3 个固定位置元素,导航栏、叠加层和高亮部分.. 现在我想将品牌带到导航栏内的亮点顶部.. 然后是下一个亮点 然后是下一个叠加层,然后是正文或导航栏..

CSS

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-color: #000;
    opacity: 0.7;
    z-index: 1000;
}

.highlight {
    position: fixed;
    top: 5px;
    left: 5px;
    width: 200px;
    height: 50px;
    background: #efefef;
    z-index: 1100;
    border-radius: 5px;

}

.nav-fixed {
    background: #333;
    height: 60px;
    position: fixed;
    top: 0;
    padding: 0 20px;
    left: 0;
    right: 0;
}

.brand {
    color: #fff;
    font-size: 20px;
    line-height: 60px;
    display: inline-block;
    z-index: 1200;
    position: relative;
}
.menu {
    float: right;
}

.menu ul {
    list-style-type: none;
    margin: 0;
}

.menu ul li {
    display: inline-block;
    line-height: 60px;
    margin: 0 5px;
    color: #fff;
    cursor: pointer;

 }

限制是我无法更改标记的顺序。这是小提琴。请随意编辑。

http://jsfiddle.net/bjcth/

【问题讨论】:

  • 如果您想以这种方式重新排列元素,则非常有必要更改标记的顺序。
  • 哈哈,看起来确实像功课。知道为什么,因为代码太整洁了:D

标签: html css position z-index


【解决方案1】:

给你。现在导航栏在菜单包装上。

.brand {
 color: #000;
 font-size: 50px;
 line-height: 100px;
 float:left;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    相关资源
    最近更新 更多