2014-10-26 68 views
0

我不明白为什么我的元素(标志,菜单,信息框)在淡灰色的容器之外。你可以帮帮我吗?非常感谢为什么我的元素在他们的容器之外?

参见:http://jsfiddle.net/vqoudo6d/3/

enter image description here

HTML:

<header class="header"> 
    <div class="header-wrapper"> 
     <img class="header-logo" src="http://lorempixel.com/output/fashion-q-g-284-119-5.jpg"> 
     <nav class="header_nav"> 
      <ul class="header_nav-wrapper"> 
       <li class="header_nav-item"> <a id="aboutOpen" class="header_nav-item-a" href="jkk">l'Atelier</a> 

       </li> 
       <li class="header_nav-item"> <a class="header_nav-item-a header_nav-item-a--btn" href="jkjks" target="_blank">La Carte des soins</a> 

       </li> 
       <li class="header_nav-item"> <a class="header_nav-item-a header_nav-item-a--btn" href="jkjks" target="_blank">Contact</a> 

       </li> 
      </ul> 
     </nav> 
    </div> 
    <div class="infos-pratiques clearfix"> 
     <p class="info-pratiques-tag">Informations pratiques</p> 
     <div class="info-pratiques-content"> 
      <p>3 rue dfdsf 
       <br>sdsqdssdd</p> 
      <p>Lundi: 
       <br>Mardi: 
       <br>Mercredi: 
       <br>Jeudi</p> 
     </div> 
    </div> 
</header> 
<div class="slider"> 
    <ul class="slider__wrapper"> 
     <li class="slider__item"> 
      <div class="box" style="background-image:url(images/test.jpg);background-size: cover; 
    background-repeat: no-repeat; background-position: 50% 50%;"></div> 
     </li> 
     <li class="slider__item"> 
      <div class="box" style="background-image:url(images/test2.jpg);background-size: cover; 
    background-repeat: no-repeat; background-position: 50% 50%;"></div> 
     </li> 
    </ul> 
</div> 

CSS:

.slider { 
    position: relative; 
    margin-left: auto; 
    margin-right: auto; 
    width: 90%; 
    height: 550px; 
    background: #eee; 
    overflow: hidden; 
    box-shadow: 0 2px 5px rgba(0, 0, 0, .5); 
    max-width: 1200px; 
} 
.slider__wrapper { 
    height: 100%; 
    list-style: none; 
    overflow: hidden; 
    *zoom: 1; 
    -webkit-backface-visibility: hidden; 
    -webkit-transform-style: preserve-3d; 
} 
.slider__item { 
    height: 100%; 
    float: left; 
    clear: none; 
} 
.slider__arrows-item { 
    position: absolute; 
    display: block; 
    margin-bottom: -20px; 
    padding: 20px; 
} 
.slider__arrows-item--right { 
    bottom: 50%; 
    right: 30px; 
} 
.slider__arrows-item--left { 
    bottom: 50%; 
    left: 30px; 
} 
.slider__nav { 
    position: absolute; 
    bottom: 30px; 
} 
.slider__nav-item { 
    width: 12px; 
    height: 12px; 
    float: left; 
    clear: none; 
    display: block; 
    margin: 0 5px; 
    background: #fff; 
} 
.slider__nav-item--current { 
    background: #ccc; 
} 
.slider__nav-item:hover { 
    background: #ccc; 
} 
.box { 
    width: 100%; 
    height: 100%; 
} 
.header { 
    z-index: 999; 
    width: 100%; 
    margin-left: auto; 
    margin-right: auto; 
    position: absolute; 
} 
.header-wrapper { 
    padding: 54px 60px; 
} 
.header-logo { 
    float: left; 
    clear: none; 
} 
.header_nav { 
    float: right; 
    clear: none; 
    font-family:'Maven Pro', sans-serif; 
    font-weight: normal; 
} 
.header_nav-wrapper { 
    list-style: none; 
} 
.header_nav-item { 
    margin-left: 22px; 
    float: left; 
    clear: none; 
} 
.header_nav-item-a { 
    color: #474032; 
    text-decoration: none; 
} 
.header_nav-item-a:hover { 
    color: #eee; 
} 
.header_nav-item-a--btn { 
    padding: 16px 18px; 
    border-radius: 5px; 
    border: 1px solid #474032; 
    background-color: transparent; 
} 
.header_nav-item-a--donate { 
    margin-top: -18px; 
} 
.header_nav-item-a--btn:hover { 
    border: 1px solid #eee; 
} 


    .info-pratiques-content { 
     float: left; 
     clear: both; 
     margin-top: 14px; 
     margin-left: 4.52489%; 
     font-size: 13px; 
     line-height: 1.38; 
     color: #433d2b; 
    } 
    .info-pratiques-content p { 
     margin-bottom: 1em; 
    } 
    .info-pratiques-tag { 
     margin-top: 14px; 
     margin-right: auto; 
     margin-left: auto; 
     padding-top: 2px; 
     padding-right: 2px; 
     padding-bottom: 2px; 
     padding-left: 2px; 
     background-color: #9d926a; 
     font-size: 13px; 
     font-weight: 400; 
     line-height: 1.38; 
     text-align: center; 
     text-transform: uppercase; 
     color: rgb(65, 61, 45); 
    } 
    .infos-pratiques { 
     position: absolute; 
     top: 217px; 
     right: 5.1984375%; 
     z-index: 26; 
     width: 221px; 
     height: 200px; 
     background-color: rgb(222, 222, 222); 
     opacity: 0.91; 
    } 
+0

过多的绝对定位...他们是更好的布局方法[** ** LearnLayout.com(http://learnlayout.com /) – 2014-10-26 18:59:27

+0

将边框添加到容器中,您将看到其大小。或者通过“检查元素”。 – Cheery 2014-10-26 19:23:07

回答

0

max-widthbackground都在.slider,但你的头不在里面。只需将背景和最大宽度添加到正文,一切都应该很好。

另外请记住,绝对定位的元素总是相对于最接近的非静态元素(position: fixed, relative, absolute)。

编辑:我也同意Paulie_D的评论,尽量减少绝对定位

+0

谢谢。不幸的是,修改身体会对我有一定的附带影响。我试图在.header上设置宽度和最大宽度,但是在这种情况下,尽管有自动边距,标题仍然是左对齐的。你知道为什么吗?谢谢.header {margin_left:auto; margin-right:auto; position:absolute; 宽度:90%; z-index:999; } – Greg 2014-10-26 19:39:32

+0

如果你设置了绝对的东西,你应该总是至少定义两个位置('top','left','right'和'bottom') 所以在你的情况下你可以添加'top:0;左:0;正确:0;'。结合'margin:0 auto;'你的头部会居中。但不幸的是不在ie8中:) - 但是当您使用90%的固定宽度时,您可以使用'margin-left:10%'和'margin-right:10%'来居中标题,而不是'auto' – 2014-10-26 20:02:25

+0

当然这将是'保证金 - 左:5%'和'保证金 - 右:5%':) – 2014-10-26 20:08:15

相关问题