[英]css div with one side rotate
Do you know if is possible to create a div, with the top side rotate or inclined like this image:你知道是否可以创建一个 div,顶部旋转或倾斜,如下图:
As you can see, the top border of the black div have a inclination, but I don't know if this is possible or how to make this.如您所见,黑色 div 的顶部边框有一个倾斜度,但我不知道这是否可能或如何制作。
Thanks for your help.谢谢你的帮助。
You can't make a single shape that looks like that but you can fake it with a rectangle and a triangle.你不能制作一个看起来像这样的形状,但你可以用一个矩形和一个三角形来伪造它。 Something like this:
像这样的东西:
HTML HTML
<div class='shape'></div>
CSS CSS
.shape {
position: relative;
height: 100px;
width: 500px;
background: black;
margin-top: 120px;
}
.shape:before {
position: absolute;
content: '';
width: 0;
height: 0;
left: 0;
top: -20px;
border-bottom: 20px solid black;
border-right: 500px solid rgba(255, 255, 255, 0);
/* Maintain smooth edge of triangle in FF */
-moz-transform: scale(.9999);
}
You can use clip-path CSS property to make the shapes you want.您可以使用 clip-path CSS 属性来制作您想要的形状。
For the image shown below, here's the clip-path对于下面显示的图像,这里是剪辑路径
clip-path: polygon(0 0, 100% 20%, 100% 100%, 0 100%); /* polygon(point1, point2, point3, point4) */
Each point - X and Y where X is calculated from the left side of the screen and Y from the top.每个点 - X 和 Y,其中 X 从屏幕左侧计算,Y 从顶部计算。
For example, XY - 0 0 (means the point1 is 0px from left and 0px from top)例如,XY - 0 0(表示点 1 距左侧 0px,距顶部 0px)
You can make use of the clip-path calculator to make the shapes you like and copy the CSS related to that here https://bennettfeely.com/clippy/您可以使用剪辑路径计算器来制作您喜欢的形状并在此处复制与此相关的 CSS https://bennettfeely.com/clippy/
Resources:资源:
https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path
https://www.w3schools.com/cssref/css3_pr_clip-path.asp https://www.w3schools.com/cssref/css3_pr_clip-path.asp
If you want to rotate the div, then make use of transform and rotate property as shown here https://3dtransforms.desandro.com/perspective如果要旋转 div,请使用变换和旋转属性,如下所示https://3dtransforms.desandro.com/perspective
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.