html - 如何在 CSS 中创建彼此相邻的多边形形状

标签 html css css-shapes

我创建了一个多边形三 Angular 形,我想将它们堆叠在一起

我使用了 shape-outside,但它似乎不起作用。 我希望它是动态的,这样就可以添加更多内容而无需更改代码

div:nth-child(odd) {
  width: 280px;
  height: 280px;
  background: #1e90ff;
  -webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  display: inline-block;
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
  background-size: cover;
  float: left;
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  shape-outside: polygon(50% 0%, 0% 100%, 100% 100%);
}

div:nth-child(even) {
  width: 280px;
  height: 280px;
  background: #1e90ff;
  display: inline-block;
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
  background-size: cover;
  float: left;
  -webkit-clip-path: polygon(50% 100%, 0 0, 100% 0);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
  shape-outside: polygon(50% 100%, 0 0, 100% 0);
  left: -137px;
}


div {
  position: relative;
}
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>

最佳答案

只需将 margin-right: -274px; 添加到 div:nth-child(even) 即可。

div:nth-child(odd) {
  width: 280px;
  height: 280px;
  background: #1e90ff;
  -webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  display: inline-block;
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
  background-size: cover;
  float: left;
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  shape-outside: polygon(50% 0%, 0% 100%, 100% 100%);
}

div:nth-child(even) {
  width: 280px;
  height: 280px;
  margin-right: -274px;
  background: #1e90ff;
  display: inline-block;
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
  background-size: cover;
  float: left;
  -webkit-clip-path: polygon(50% 100%, 0 0, 100% 0);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
  shape-outside: polygon(50% 100%, 0 0, 100% 0);
  left: -137px;
}


div {
  position: relative;
}
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>

关于html - 如何在 CSS 中创建彼此相邻的多边形形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29769955/

相关文章:

html - 如何仅使用 CSS 制作 donut 片段

HTML 水平滚动

html - 两个方向的中心图像

html - 使用 CSS 绘制三 Angular 形裁剪形状

html - 创建一个倾斜的三 Angular 形

添加其他 Div 时 CSS 文本对齐中心不起作用

javascript - jquery 在页面加载时设置 href 链接

javascript - 使用 PHP 获取 div 类的内容并存储到数据库表

javascript - postcss-preset-env : end value has mixed support, 考虑改用 flex-end

javascript - 使用 JavaScript 创建 MDL 复选框