Ric*_*ard 11 css linear-gradients css3 responsive-design css-shapes
我试图让图像的底部指向.我试图通过在底部生成两个三角形来获得此效果.他们必须有回应.并且在搜索了整个互联网之后,有很多例子对我的要求不起作用,这是迄今为止我设法制作的最好的例子.
body,
html {
height: 100%
}
.image {
width: 1410px;
margin-right: auto;
margin-left: auto;
height: 500px;
overflow: hidden;
position: relative;
}
.pointer {
height: 50px;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
}
.triangleWrapper {
width: 50%;
height: 50px;
float: left;
}
.lefttriangle {
width: 100%;
height: 10px;
left: 0px;
top: 0px;
background-image: linear-gradient(to right top, #ffffff 50%, transparent 50%);
}
.righttriangle {
width: 100%;
height: 10px;
right: 0px;
top: 0px;
background: linear-gradient(to left top, #ffffff 50%, transparent 50%)
}Run Code Online (Sandbox Code Playgroud)
<div class="image">
<img src="http://placekitten.com/1410/500">
<div class="pointer">
<div class="triangleWrapper">
<div style="height: 100%;" class="lefttriangle"></div>
</div>
<div class="triangleWrapper">
<div style="height: 100%;" class="righttriangle"></div>
</div>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
它完全符合我的要求,因为它无需媒体查询即可响应.但它在三角形线上的锯齿状边缘不是90度.
如果不是所有现代浏览器,我如何在大多数情况下生成平滑线?我不是要求向后兼容性.
任何帮助是极大的赞赏!
Har*_*rry 19
不幸的是,这总是发生在我们使用有角度的linear-gradient图像时,目前克服这种行为的唯一方法似乎是避免颜色的硬停止(也就是说,不要将一种颜色的停止点作为一个颜色的起点.下一个).使第二种颜色从第一种颜色的停止点开始稍微偏离会产生模糊区域并使其看起来更平滑.这仍然不是100%完美,但比锯齿状边缘更好.
.lefttriangle {
width: 100%;
height: 10px;
left: 0px;
top: 0px;
background-image: linear-gradient(to right top, #ffffff 48%, transparent 50%); /* note the change of stop and start points */
}
.righttriangle {
width: 100%;
height: 10px;
right: 0px;
top: 0px;
background: linear-gradient(to left top, #ffffff 48%, transparent 50%); /* note the change of stop and start points */
}
Run Code Online (Sandbox Code Playgroud)
body,
html {
height: 100%
}
.image {
width: 1410px;
margin-right: auto;
margin-left: auto;
height: 500px;
overflow: hidden;
position: relative;
}
.pointer {
height: 50px;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
}
.triangleWrapper {
width: 50%;
height: 50px;
float: left;
}
.lefttriangle {
width: 100%;
height: 10px;
left: 0px;
top: 0px;
background-image: linear-gradient(to right top, #ffffff 48%, transparent 50%);
}
.righttriangle {
width: 100%;
height: 10px;
right: 0px;
top: 0px;
background: linear-gradient(to left top, #ffffff 48%, transparent 50%);
}Run Code Online (Sandbox Code Playgroud)
<div class="image">
<img src="http://placekitten.com/1410/500">
<div class="pointer">
<div class="triangleWrapper">
<div style="height: 100%;" class="lefttriangle"></div>
</div>
<div class="triangleWrapper">
<div style="height: 100%;" class="righttriangle"></div>
</div>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
替代实施:
剪辑路径:您还可以使用clip-path功能来产生类似的效果.使用的优点clip-path是它既响应又产生透明切割.基于SVG的clip-path浏览器支持比CSS版本更好.但是在IE中尚不支持.
body,
html {
height: 100%
}
.image {
width: 1410px;
margin-right: auto;
margin-left: auto;
height: 500px;
overflow: hidden;
position: relative;
}
.css-clip {
-webkit-clip-path: polygon(0% 0%, 0% 90%, 50% 100%, 100% 90%, 100% 0%);
clip-path: polygon(0% 0%, 0% 90%, 50% 100%, 100% 90%, 100% 0%);
}
.svg-clip {
-webkit-clip-path: url(#clipper);
-moz-clip-path: url(#clipper);
clip-path: url(#clipper);
}Run Code Online (Sandbox Code Playgroud)
<!-- CSS Clip-path - Lower browser support -->
<div class="image css-clip">
<img src="http://placekitten.com/1410/500">
</div>
<!-- SVG Clip-path - Better browser support -->
<svg width="0" height="0">
<defs>
<clipPath clipPathUnits="objectBoundingBox" id="clipper">
<path d="M0,0 0,0.9 0.5,1 1,0.9 1,0z" />
</clipPath>
</defs>
</svg>
<div class="image svg-clip">
<img src="http://placekitten.com/1410/500">
</div>Run Code Online (Sandbox Code Playgroud)
使用CSS转换:您也可以尝试使用此答案中提到的方法.它在左侧实现了尖锐的效果,但应该很容易使其适应在底部产生尖锐的效果.
body,
html {
height: 100%
}
.image {
width: 1410px;
margin-right: auto;
margin-left: auto;
height: 500px;
overflow: hidden;
position: relative;
}
.top-container,
.bottom-container {
position: absolute;
bottom: 0px;
height: 100%;
width: 50%;
overflow: hidden;
backface-visibility: hidden;
}
.top-container {
left: 0px;
transform-origin: right bottom;
transform: skewY(10deg);
}
.bottom-container {
right: 0px;
transform-origin: left bottom;
transform: skewY(-10deg);
background-position: 0% 100%;
}
.top-container:after,
.bottom-container:after {
position: absolute;
content: '';
height: 100%;
width: 100%;
bottom: -62px; /* tan(10) * (width/2) / 2 */
background: url(http://placekitten.com/1410/500);
background-size: 200% 100%;
}
.top-container:after {
left: 0px;
transform: skewY(-10deg);
}
.bottom-container:after {
right: 0px;
transform: skewY(10deg);
background-position: 100% 0%;
}Run Code Online (Sandbox Code Playgroud)
<div class="image">
<div class='top-container'></div>
<div class='bottom-container'></div>
</div>Run Code Online (Sandbox Code Playgroud)
kat*_*uis 13
刚刚在codepen上找到了一个非常好的解决方案 calc(50% - 1px)
https://codepen.io/hellonico/pen/xEYXmL
background: linear-gradient(7deg, currentColor calc(50% - 1px), transparent 50%);
Run Code Online (Sandbox Code Playgroud)
没有任何模糊,只有光滑的边缘
编辑:..显然不在Safari?..