【问题标题】:Div following wrapper div floats behind wrapper包装器后的 div div 浮动在包装器后面
【发布时间】:2014-12-18 22:51:04
【问题描述】:

我正在开发一个流体网格 (DreamWeaver CC) 网站。我有一个包含使用 z-index 堆叠元素的 header-Wrapper div。我现在尝试在 header-Wrapper 之后添加一个 div,但这个 div 浮动在 header-Wrapper 后面。这是我第一次使用 z-index,所以我很困惑。

我已尝试为 mobileNav div 定位和显示 css 元素,还尝试为 header-wrapper 使用 height 元素。没有什么。 mobileNav div 似乎完全忽略了 header-Wrapper 并且表现得好像它是 gridContainer 中的第一个 div。

感谢您的帮助

网站:miki.nantucket.net/redac-2.php


html

<body>
    <div class="gridContainer clearfix">
        <div id="header-wrapper" class="fluid">
        <div id="rotation" class="fluid "><?php include  $_SERVER['DOCUMENT_ROOT']."/includes/layout/rotations.php" ?></div>
        <div id="Weather" class="fluid "><?php include  $_SERVER['DOCUMENT_ROOT']."/includes/layout/weather.php" ?></div>
        <div id="Navigation" class="fluid "><ul>
        <li>Nav1</li>
        <li>Nav2</li>
        <li>Nav3</li>
        <li>Nav4</li>
        <li>Nav5</li>
        <li>Nav6</li>
        <li>This is not styled yet</li>
        </ul></div>
      </div><!--end header-wrapper-->
      <div id="mobileNav" class="fluid">This is the content for Layout Div Tag "mobileNav"</div>
     </div>
 </body>

CSS

.fluid {
    clear: both;
    margin-left: 0;
    width: 100%;
    float: left;
    display: block;
}

.fluidList {
    list-style:none;
    list-style-image:none;
    margin:0;
    padding:0;        
}

/* Mobile Layout: 480px and below. */

.gridContainer {
    margin-left: auto;
    margin-right: auto;
    width: 92.625%;
    padding-left: 0;
    padding-right: 0;
    clear: none;
    float: none;
    background-color:#FBFAF6;
}
#header-wrapper {
    position:relative;
    width: 100%;
    padding:0;
    margin:0;
}
#rotation {
    position:absolute;
    z-index:1;

}
#Navigation {
    display:none;   
    width: 100%;
}   
#Weather {
    text-align:right;
    font-size:13px;
    padding:5px 0px 10px 0px;
    position:absolute;
    z-index:50;
    top:0px;
    left:0;
    background: #4b829f;
    background: rgba(75,134,159, .8);
    color: #ffffff;
}
#mobileNav {
    position:relative;
}
.zeroMargin_mobile {
margin-left: 0;
}
.hide_mobile {
display: none;
}

/* Tablet Layout: 481px to 768px. Inherits styles from: Mobile Layout. */

@media only screen and (min-width: 481px) {

.gridContainer {
    width: 93.4166%;
    padding-left: 0;
    padding-right: 0;
    clear: none;
    float: none;
    margin-left: auto;
}
#header-wrapper {
}
#rotation {
}
#Navigation {
    display:block;
    position:absolute;
    z-index:100;
    top:49px;
    left:0;
    background: #4b8a9f;
  background: rgba(75,134,159, .8);
    color: #ffffff;
    width: 23.7288%;
}
#Weather {
}
#mobileNav {
}
.hide_tablet {
display: none;
}
.zeroMargin_tablet {
margin-left: 0;
}
}

/* Desktop Layout: 769px to a max of 1232px.  Inherits styles from: Mobile Layout and Tablet Layout. */

@media only screen and (min-width: 769px) {

.gridContainer {
    width: 88.875%;
    max-width: 1232px;
    padding-left: 0;
    padding-right: 0;
    margin: auto;
    clear: none;
    float: none;
    margin-left: auto;
}
#header-wrapper {
}
#rotation {
}
#Navigation {
    display:block;
    position:absolute;
    z-index:100;
    top:49px;
    left:0;
    background: #4b8a9f;
    background: rgba(75,134,159, .8);
    color: #ffffff;
    width: 17.7215%;
}
#Weather {
}
#mobileNav {
}
.zeroMargin_desktop {
margin-left: 0;
}
.hide_desktop {
display: none;
}

}

包含响应式滑块的 CSS

/*responsive hero slider*/
.rslides {
  position: relative;
  list-style: none;
  overflow: hidden;
  width: 100%;
  padding: 0;
  margin: 0;
  }

.rslides li {
  -webkit-backface-visibility: hidden;
  position: absolute;
  display: none;
  width: 100%;
  left: 0;
  top: 0;
  }

.rslides li:first-child {
  position: relative;
  display: block;
  float: left;
  }

.rslides img {
  display: block;
  height: auto;
  float: left;
  width: 100%;
  border: 0;
  }
  .caption {
  position: absolute;
  display: block;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px;
  margin:0;
  text-align: center;
  background: #4b8a9f;
  background: rgba(75,134,159, .8);
  color: #ffffff;
  font-size:18px;
  font-stretch:expanded;
}

【问题讨论】:

    标签: css z-index fluid-layout


    【解决方案1】:

    谢谢。由于各种元素,我确实需要绝对定位,但您关于允许标题包装器中的空间的评论给了我一个想法。我将图像放入 header-wrapper 中,到处摆弄 z-index 属性。可能不是最优雅的方式,但它确实有效!

    谢谢。


    html

    <div class="gridContainer clearfix">
            <div id="header-wrapper" class="fluid">
                   <div id="rotation" class="fluid "><?php include  $_SERVER['DOCUMENT_ROOT']."/includes/layout/rotations.php" ?></div>
            <div id="Weather" class="fluid "><?php include  $_SERVER['DOCUMENT_ROOT']."/includes/layout/weather.php" ?></div>
            <div id="Navigation" class="fluid "><ul class="navBump">
            <li>Nav1</li>
            <li>Nav2</li>
            <li>Nav3</li>
            <li>Nav4</li>
            <li>Nav5</li>
            <li>Nav6</li>
            <li>This is not styled yet</li>
            </ul></div>
     <div id="LogoWrapper" class="fluid "><div id="Logo" class="fluid "><img src="images/sitewide/Logo.png"></div><div id="LogoTag" class="fluid "><?php include  $_SERVER['DOCUMENT_ROOT']."/includes/layout/logtag.php" ?></div></div>        
         <img src="images/rotations/redac2/image1a.jpg">
          </div><!--end header-wrapper-->
          <div id="mobileNav" class="fluid">This is the content for Layout Div Tag "mobileNav"</div>
         </div>
    

    CSS

    .fluid {
        clear: both;
        margin-left: 0;
        width: 100%;
        float: left;
        display: block;
    }
    
    .fluidList {
        list-style:none;
        list-style-image:none;
        margin:0;
        padding:0;        
    }
    
    /* Mobile Layout: 480px and below. */
    
    .gridContainer {
        margin-left: auto;
        margin-right: auto;
        width: 92.625%;
        padding-left: 0;
        padding-right: 0;
        clear: none;
        float: none;
        background-color:#FBFAF6;
    }
    #header-wrapper {
        position:relative;
        width: 100%;
        padding:0;
        margin:0;
    }
    #header-wrapper img {
        position:relative;
        z-index:1;
    }
    #rotation {
        position:absolute;
        top:0;
        left:0;
        z-index:5;  
        margin-left: 0; 
        width: 100%;
    }
    #Navigation {
        display:none;   
        width: 31.0344%;
        margin-left: 0;
    }
    
    #Weather {
        text-align:right;
        font-size:13px;
        padding:5px 0px 10px 0px;
        position:absolute;
        z-index:50;
        top:0px;
        left:0;
        background: #4b829f;
        background: rgba(75,134,159, .8);
        color: #ffffff;
        margin-left: 0;
        width: 100%;
    }
    #mobileNav {
        z-index:0;
        width: 100%;
        margin-left: 0;
    }
    #LogoWrapper {
        position:absolute;
        top:0;
        left:0;
        z-index:1000;
    }
    #Logo {
    }
    #LogoTag {
        font-size:12px;
        color:#797979;
    }
    .zeroMargin_mobile {
    margin-left: 0;
    }
    .hide_mobile {
    display: none;
    }
    
    /* Tablet Layout: 481px to 768px. Inherits styles from: Mobile Layout. */
    
    @media only screen and (min-width: 481px) {
    
    .gridContainer {
        width: 93.4166%;
        padding-left: 0;
        padding-right: 0;
        clear: none;
        float: none;
        margin-left: auto;
    }
    #header-wrapper {
    }
    #rotation {
        width: 100%;
        margin-left: 0;
    }
    #Navigation {
        display:block;
        position:absolute;
        z-index:100;
        top:49px;
        left:0;
        background: #4b8a9f;
        background: rgba(75,134,159, .8);
        color: #ffffff;
        width: 23.7288%;
        margin-left: 0;
    }
    #Weather {
        width: 100%;
        margin-left: 0;
    }
    #mobileNav {
        margin-left: 0;
        width: 100%;
    }
    #LogoWrapper {
    }
    #Logo {
    }
    #LogoTag {
    }
    .hide_tablet {
    display: none;
    }
    .zeroMargin_tablet {
    margin-left: 0;
    }
    }
    
    /* Desktop Layout: 769px to a max of 1232px.  Inherits styles from: Mobile Layout and Tablet Layout. */
    
    @media only screen and (min-width: 769px) {
    
    .gridContainer {
        width: 88.875%;
        max-width: 1232px;
        padding-left: 0;
        padding-right: 0;
        margin: auto;
        clear: none;
        float: none;
        margin-left: auto;
    }
    #header-wrapper {
    }
    #rotation {
        width: 100%;
        margin-left: 0;
    }
    #Navigation {
        display:block;
        position:absolute;
        z-index:100;
        top:49px;
        left:0;
        background: #4b8a9f;
        background: rgba(75,134,159, .8);
        color: #ffffff;
        width: 24.0506%;
        margin-left: 0;
    }
    #Weather {
        width: 100%;
        margin-left: 0;
    }
    #mobileNav {
        width: 100%;
        margin-left: 0;
    }
    #LogoWrapper {
    }
    #Logo {
    }
    #LogoTag {
    }
    .zeroMargin_desktop {
    margin-left: 0;
    }
    .hide_desktop {
    display: none;
    }
    }
    

    旋转图片 CSS

    .rslides {
      position: relative;
      list-style: none;
      overflow: hidden;
      width: 100%;
      padding: 0;
      margin: 0;
      }
    
    .rslides li {
      -webkit-backface-visibility: hidden;
      position: absolute;
      display: none;
      width: 100%;
      left: 0;
      top: 0;
      }
    
    .rslides li:first-child {
      position: relative;
      display: block;
      float: left;
      }
    
    .rslides img {
      display: block;
      height: auto;
      float: left;
      width: 100%;
      border: 0;
      }
      .caption {
      position: absolute;
      z-index:25;
      display: block;
      bottom: 0;
      left: 0;
      right: 0;
      padding: 10px;
      margin:0;
      text-align: center;
      background: #4b829f;
      background: rgba(75,134,159, .8);
      color: #ffffff;
      font-size:18px;
      font-stretch:expanded;
    }
    

    【讨论】:

      【解决方案2】:

      您的#mobileNav 出现在所有#header-wrapper 内容的后面,因为所有#header-wrapper 内容都使用position: absolute;。像#Weather#Navigation 这样的绝对定位元素会从文档流中移除,就好像它们从未存在过一样。您可能只想将它们浮动到它们的位置,但如果需要绝对定位,那么您需要在父元素中使用一些空间来考虑它们。

      【讨论】:

        猜你喜欢
        • 2011-08-02
        • 2014-06-10
        • 1970-01-01
        • 1970-01-01
        • 2017-05-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多