拆开各种末端多个偏斜的图像

发布于 2025-02-05 11:37:28 字数 3924 浏览 0 评论 0原文

我问这个

”在此处输入图像说明”

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

与另一个线程的答案相比,我的这件代码量很长,但它允许我为输入的每张图片调整大小。

我现在要做的是让最左端的box1和此container环境的最右端 box6 仅在此分类的内部。就像这张海报想要获得的结果一样:仅一侧一个元素

我已经尝试了几个方法了几个小时,但我似乎没有运气更改box1box6在不翘曲图像的同时偏斜。

I asked this question earlier asking how to skew an assortment of images. I was able to get very satisfying results

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>

While my this snipped of code is lengthy compared to the answered one from the other thread, it allows me to resize for each picture I input.

What I am trying to do now is to have the far left end box1 and the far right end box6 of this container environment to skewed only in the inner portion of this assortment. It is kind of like the result this poster is wanting to get: Skew one side only of an element.

I have been attempting several methods of this for a couple hours and I do not to seem to have luck altering box1 and box6 To have one side skewed while not warping the images.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

婴鹅 2025-02-12 11:37:28

新答案

这是我写的文章的更好版本: https://css-tricks.com/css-grid-and-custom-shapes-part-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>

New answer

Here is a better version from an article I wrote: https://css-tricks.com/css-grid-and-custom-shapes-part-2/

You can have hover effect and gap as well

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


Old answer

You can use negative margin for last and first one to hide half the element:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文