CSS平行四边形内的图像

时间:2019-07-02 20:29:58

标签: html css wordpress

我正在创建一个带有平行四边形div的Slick Carousel Slider和每个幻灯片的图像。我无法创建平行四边形div,但是,即使我对它应用了负度,平行四边形div内的图像也会偏斜。这是我的代码:

html:

    <!-- Home Main Slider -->
    <div class="home-main-slider-container">
      <?php if(have_rows('home')): ?>
        <?php while(have_rows('home')): the_row(); ?>
        <div class="main-slider">
            <?php if(have_rows('main_slider')): ?>
              <?php while(have_rows('main_slider')): the_row(); ?>
                <?php 
                  $bg = get_sub_field('image');
                 ?>
                <div class="main-slide">
                 <div class="service-parallelogram">
                   <div class="service-img" style="background:url(<?php echo $bg['url']; ?>);"></div>
                 </div>
                </div>
              <?php endwhile; ?>
            <?php endif; ?>
          </div>
        <?php endwhile; ?>
      <?php endif; ?>
    </div>
    <!-- /Home Main Slider -->

css:

.home-main-slider-container {
  .main-slider {
    .main-slide {
      .service-parallelogram {
        width: 600px;
        height: 750px;
        -webkit-transform: skewX(20deg);
        -ms-transform: skewX(20deg);
        transform: skewX(20deg);
        .service-img {
          -webkit-transform: skewX(-20deg);
          -ms-transform: skewX(-20deg);
          transform: skewX(-20deg);
          background-size: cover !important;
          background-position: center !important;
          width: 100%;
          height: 100%;
        }
      }
    }
  }
}

0 个答案:

没有答案