【问题标题】:Unskewing the ends of an assortment multiple skewed images取消倾斜分类多个倾斜图像的末端
【发布时间】:2018-03-15 00:04:35
【问题描述】:

我之前问过这个question,询问如何扭曲各种图像。我能够得到非常令人满意的结果

.container {
  font-size: 0;
  height: 215px;
  margin: 30px 50px;
  text-align: center;
  color: black;
}

.box1 {
  font-size: initial;
  width: calc(100% / 6);
  height: 100%;
  border: 3px solid;
  box-sizing: border-box;
  transform: skew(-25deg);
  position: relative;
  overflow: hidden;
  display: inline-block;
}

.box2 {
  font-size: initial;
  width: calc(100% / 6);
  height: 100%;
  border: 2.5px solid;
  box-sizing: border-box;
  transform: skew(-25deg);
  position: relative;
  overflow: hidden;
  display: inline-block;
}

.box3 {
  font-size: initial;
  width: calc(100% / 6);
  height: 100%;
  border: 2.5px solid;
  box-sizing: border-box;
  transform: skew(-25deg);
  position: relative;
  overflow: hidden;
  display: inline-block;
}

.box4 {
  font-size: initial;
  width: calc(100% / 6);
  height: 100%;
  border: 2.5px solid;
  box-sizing: border-box;
  transform: skew(-25deg);
  position: relative;
  overflow: hidden;
  display: inline-block;
}

.box5 {
  font-size: initial;
  width: calc(100% / 6);
  height: 100%;
  border: 2.5px solid;
  box-sizing: border-box;
  transform: skew(-25deg);
  position: relative;
  overflow: hidden;
  display: inline-block;
}

.box6 {
  font-size: initial;
  width: calc(100% / 6);
  height: 100%;
  border: 2.5px solid;
  box-sizing: border-box;
  transform: skew(-25deg);
  position: relative;
  overflow: hidden;
  display: inline-block;
}

.box1 span {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -100%;
  right: -100%;
  transform: skew(25deg);
  background-position: center;
  background-size: cover;
}

.box2 span {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -50%;
  right: -50%;
  transform: skew(25deg);
  background-position: center;
  background-size: cover;
}

.box3 span {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -50%;
  right: -50%;
  transform: skew(25deg);
  background-position: center;
  background-size: cover;
}

.box4 span {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -35%;
  right: -35%;
  transform: skew(25deg);
  background-position: center;
  background-size: cover;
}

.box5 span {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -50%;
  right: -50%;
  transform: skew(25deg);
  background-position: center;
  background-size: cover;
}

.box6 span {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -35%;
  right: -35%;
  transform: skew(25deg);
  background-position: center;
  background-size: cover;
}
<div class="container">
  <div class="box1"><span style="background-image:url(illustris1.png)"></span></div>
  <div class="box2"><span style="background-image:url(gal.png)"></span></div>
  <div class="box3"><span style="background-image:url(laniakea.jpg)"></span> </div>
  <div class="box4"><span style="background-image:url(globularstar.jpg)"></span></div>
  <div class="box5"><span style="background-image:url(elliptical.jpg)"></span></div>
  <div class="box6"><span style="background-image:url(illustris2.png)"></span></div>
  <div class="container mid"></div>
</div>

虽然我的这段代码与来自另一个线程的回答相比很长,但它允许我为我输入的每张图片调整大小。

我现在要做的是让这个container 环境的最左端box1 和最右端box6 只在这个分类的内部偏斜。这有点像这张海报想要得到的结果:Skew one side only of an element

几个小时以来,我一直在尝试几种方法,但我似乎没有运气改变 box1box6 在不扭曲图像的情况下使一侧倾斜。

【问题讨论】:

    标签: html css css-transforms


    【解决方案1】:

    您可以对最后一个和第一个使用负边距来隐藏一半元素:

    .container {
      display: flex;
      height: 150px;
      margin: 0 30px;
      overflow:hidden;
    }
    
    .box {
      flex: 1;
      border: 1px solid;
      transform: skew(-25deg);
      position: relative;
      overflow: hidden;
    }
    .box:first-child {
      margin-left:calc((100% / 5) / -2);
    }
    .box:last-child {
      margin-right:calc((100% / 5) / -2);
    }
    
    .box:after {
      content: "";
      position: absolute;
      top: 0;
      bottom: 0;
      left: -50%;
      right: -50%;
      transform: skew(25deg);
      background-image: var(--i);
      background-position: center;
    }
    <div class="container">
      <div class="box" style="--i:url(https://lorempixel.com/400/200/)"></div>
      <div class="box" style="--i:url(https://lorempixel.com/400/300/)"></div>
      <div class="box" style="--i:url(https://lorempixel.com/300/200/)"></div>
      <div class="box" style="--i:url(https://lorempixel.com/400/300/)"></div>
      <div class="box" style="--i:url(https://lorempixel.com/200/300/)"></div>
    </div>

    【讨论】:

      猜你喜欢
      • 2021-11-09
      • 2022-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      • 2014-03-30
      • 1970-01-01
      • 2013-07-19
      • 2023-03-19
      相关资源
      最近更新 更多