3

有没有人知道一种方法来创建一个响应宽度为倒锥形的 div(参见附加的代码片段),只使用 css。此外,这个 div 需要有一个重复的背景图像(模式)。

我尝试使用剪辑路径:

#div {
	height: 100%;
	width: 100%;
	-webkit-clip-path: polygon(50% 90px, 100% 0%, 100% 100%, 0 100%, 0 0);
	clip-path: polygon(50% 25%, 100% 0, 100% 100%, 0 100%, 0 0);
background: blue;
  padding-top: 160px;
}
<div id="div"></div>

这在 Safari 和 Chrome 中运行良好,但在 Mozilla、Opera 或 IE 中无法运行。有没有办法为所有相关浏览器实现?

任何帮助,将不胜感激。

4

2 回答 2

2

linear-gradient值一起使用,而不是固定角度。您也可以使用变换制作该形状,但这需要 JS 使其具有响应性。

小提琴

body {
    background-color: blue;
    margin: 0;
    padding: 0;
}
div {
    height: 150px;
    width: 100%;
    position: relative;
}
div:after, div:before {
    content:"";
    position: absolute;
    height: inherit;
    width: 50%;
}
div:before {
    left: 0;
    background: -webkit-linear-gradient(to bottom left, white 50%, transparent 50%);
    background: -moz-linear-gradient(to bottom left, white 50%, transparent 50%);
    background: -o-linear-gradient(to bottom left, white 50%, transparent 50%);
    background: linear-gradient(to bottom left, white 50%, transparent 50%);
}
div:after {
    right: 0;
    background: -webkit-linear-gradient(to bottom right, white 50%, transparent 50%);
    background: -moz-linear-gradient(to bottom right, white 50%, transparent 50%);
    background: -o-linear-gradient(to bottom right, white 50%, transparent 50%);
    background: linear-gradient(to bottom right, white 50%, transparent 50%);
}
<div></div>

于 2015-03-05T09:35:47.223 回答
0

您可以将 div 设置为隐藏溢出,然后设置 2 个带有倾斜的伪元素,每半个

.test {
  width: 400px;
  height: 300px;
  overflow: hidden;
  position: relative;
}

.test:after, .test:before {
  content: "";
  position: absolute;
  top: 0px;
  width: 50%;
  height: 100%;
}

.test:before {
  left: 0px;
  transform: skewY(15deg);
  transform-origin: top left;
  background: repeating-linear-gradient(-15deg, white 0px, lightblue 40px);

}
.test:after {
    right: 0px;
  transform: skewY(-15deg);
  transform-origin: top right;
  background: repeating-linear-gradient(15deg, white 0px, lightblue 40px);
  
 } 
<div class="test"></div>

于 2015-03-07T17:36:04.160 回答