html - 矫正多个倾斜图像分类的末端

标签 html css css-transforms

我问了这个question之前询问如何倾斜各种图像。我得到了非常满意的结果

enter image description here

.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 以使一侧倾斜而不扭曲图像。

最佳答案

新答案

这是我写的一篇文章的更好版本:https://css-tricks.com/css-grid-and-custom-shapes-part-2/

你也可以有悬停效果和间隙

.gallery {
  --s: 50px; /* control the slanted part */
  
  display: grid;
  height: 350px;
  gap: 8px;
  grid-auto-flow: column;
  place-items: center;
}
.gallery > img {
  width: 0;
  min-width: calc(100% + var(--s));
  height: 0;
  min-height: 100%;
  object-fit: cover;
  clip-path: polygon(var(--s) 0,100% 0,calc(100% - var(--s)) 100%,0 100%);
  cursor: pointer;
  transition: .5s;
}
.gallery > img:hover {
  width: 15vw; 
}
.gallery > img:first-child {
  min-width: calc(100% + var(--s)/2);
  place-self: start;
  clip-path: polygon(0 0,100% 0,calc(100% - var(--s)) 100%,0 100%);
}
.gallery > img:last-child {
  min-width: calc(100% + var(--s)/2);
  place-self: end;
  clip-path: polygon(var(--s) 0,100% 0,100% 100%,0 100%);
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  align-content: center;
  background: #ECD078;
}
<div class="gallery">
  <img src="https://picsum.photos/id/433/600/400" alt="A Bear">
  <img src="https://picsum.photos/id/582/600/400" alt="A wolf">
  <img src="https://picsum.photos/id/1074/600/400" alt="A lioness">
  <img src="https://picsum.photos/id/237/600/400" alt="A Dog">
  <img src="https://picsum.photos/id/659/600/400" alt="A kind wolf">
  <img src="https://picsum.photos/id/593/600/400" alt="A Tiger">
</div>


旧答案

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

.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>

关于html - 矫正多个倾斜图像分类的末端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49289529/

相关文章:

html - 具有相同高度的 div 和 span

用于修改 CSS 的 Javascript 在 IE 中不起作用

android - Phonegap Android 中的平滑 3d 转换

html - css3 变换 : translatex(-100%); not working properly in IE11 & Edge

javascript - 在 PHP 中获取窗帘元素 ID 的文本

html - 覆盖一半页面的 CSS 通配符

javascript - 自定义CSS开关不运行javascript函数

jquery - 在 slider 中查看 ms 图片

css - 在网页设计中何时使用图像以及何时使用背景图像?

在 Wordpress 站点中使用关键帧进行 CSS 动画/转换