此段代码如何将div置于窗口底部

想把整个swiper-container置于距窗口底部30px,但设置bottom无效,高手请赐教

<html>
 <head> 
  <meta charset="utf-8" /> 
  <link rel="stylesheet" href="http://www.swiper.com.cn/dist/css/swiper.min.css" /> 
  <style>
    body {
      font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
      font-size: 14px;
      color:#000;
      margin: 0;
      padding: 0;
    }
    .swiper-container {
      width:100%;
      height:100%;
      max-width:580px;
    }
    .swiper-slide {
      background-position: center;
      background-size: cover;
      width: 100px;
      height:100px;
    }
  </style> 
 </head> 
 <body> 
  <div class="swiper-container"> 
   <div class="swiper-wrapper"> 
    <div class="swiper-slide" style="background-color:red"></div> 
    <div class="swiper-slide" style="background-color:blue"></div> 
    <div class="swiper-slide" style="background-color:green"></div> 
    <div class="swiper-slide" style="background-color:gray"></div> 
   </div> 
  </div>  
 </body>
</html>
阅读 2.6k
4 个回答
.swiper-container {
  height:100px;
  max-width:580px;
      position: fixed;
      bottom: 30px;
      left: 50%;
  transform: translate(-50%);
}
.swiper-container {
    width: 100%;
    height: 100%;
    max-width: 580px;
    position: absolute;
    bottom: 30px;
}

你要父元素和子元素同时整个定位,他才能有效啊,这样当然不能拉

position:fixed;
bottom:30px;

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题