码迷,mamicode.com
首页 > 其他好文 > 详细

在swiper-slide中水平垂直居中元素flex实现

时间:2020-04-15 13:51:19      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:png   ini   items   bottom   pos   title   span   class   居中   

代码结构:

<!-- Swiper -->
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <div class="swiper-slide">
        <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586935483760&di=75ca9f154573e86a9ddf126c17b27bbc&imgtype=0&src=http%3A%2F%2F00.minipic.eastday.com%2F20170925%2F20170925105058_d41d8cd98f00b204e9800998ecf8427e_2.jpeg" alt="">
        <div class="swiper-title">
          <div class="title-cont">
            <div class="swiper-title-cont">
              <h2>我是主标题</h2>
              <h3>我是副标题</h3>
            </div>
            <a href="#">点击详情</a>
          </div>
        </div>
      </div>
    </div>
  </div>

样式内容:

 .swiper-container {
      width: 100%;
      height: 30%;
    }
    .swiper-slide img{
      width: 100%;
      height: 100%;
      vertical-align: top;
     }
     .swiper-title
     {
       position: absolute;
       display: flex;
       left: 0;
       right: 0;
       bottom: 0;
       top: 0;
       margin: auto;
       align-items: center;
       justify-content: center;
       font-size: 12px;
       text-align: center;
       color: #fff;
     }
     .title-cont{
       position: absolute;
        flex: 1;
     }

实现效果:

技术图片

 

在swiper-slide中水平垂直居中元素flex实现

标签:png   ini   items   bottom   pos   title   span   class   居中   

原文地址:https://www.cnblogs.com/xiaojianwei/p/12704536.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!