是否可以将 div 样式设置为梯形?
我知道可能会倾斜,但我没有找到一种方法可以使每个角倾斜特定的角度。
这是我正在从事的项目: http://map.ucf.edu/
具体查看菜单中的选项卡。现在我正在使用图像,我想为有能力的浏览器更改它。
我知道可以创建一个 CSS trapazoid,但是即使用没有内容的边框。最终结果还需要一些圆角。
编辑: 从Zoltan Toth 的解决方案 我能够实现这一目标: 演示
div {
height: 20px;
padding:2px 5px 0 5px;
color:white;
background: rgba(0,0,0,.5);
margin: 0 10px;
position: relative;
border-top-left-radius: 6px 4px;
border-top-right-radius: 6px 4px;
font-family:sans-serif;
font-size:13px;
line-height:20px;
vertical-align:bottom;
display:inline-block;
white-space:nowrap;
}
div:before {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-bottom: 19px solid rgba(0,0,0,.5);
border-left: 9px solid transparent;
position: absolute;
bottom: 0;
left: -9px;
}
div:after {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-bottom: 19px solid rgba(0,0,0,.5);
border-right: 9px solid transparent;
position: absolute;
bottom: 0;
right: -9px;
}
.b { background:black; margin:0 -7px 0 20px; }
.b:after, .b:before { border-bottom-color:black; }
I know it's possible to skew but I don't see a way to skew each corner with a particular degree.
Here's the project I'm working on: http://map.ucf.edu/
Looking specifically at the tabs within the menu. Right now I'm using images, I would like to change that for capable browsers.
I know it's possible to create a CSS trapazoid, but that is using borders without content. The end result also needs a bit of rounded corners.
edit:
Starting with Zoltan Toth's solution I was able to achieve this: demo
div {
height: 20px;
padding:2px 5px 0 5px;
color:white;
background: rgba(0,0,0,.5);
margin: 0 10px;
position: relative;
border-top-left-radius: 6px 4px;
border-top-right-radius: 6px 4px;
font-family:sans-serif;
font-size:13px;
line-height:20px;
vertical-align:bottom;
display:inline-block;
white-space:nowrap;
}
div:before {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-bottom: 19px solid rgba(0,0,0,.5);
border-left: 9px solid transparent;
position: absolute;
bottom: 0;
left: -9px;
}
div:after {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-bottom: 19px solid rgba(0,0,0,.5);
border-right: 9px solid transparent;
position: absolute;
bottom: 0;
right: -9px;
}
.b { background:black; margin:0 -7px 0 20px; }
.b:after, .b:before { border-bottom-color:black; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是可能的,这是粗略的想法:
It is possible, here is the rough idea:
我们可以使用
linear-gradient()
在矩形元素上绘制梯形形状。这个技巧使用了将整个形状分成不同部分的想法,然后在背景上独立绘制每个形状。
We can use
linear-gradient()
to draw trapezoidal shape on rectangular element.This trick uses the idea of dividing whole shape in different parts and then draws each shape on the background independently.
现在,您可以使用 clip-path 和 多边形

在这个例子中我们有 4 个参数。
第一个参数(左上)
x -> 15%
y-> 0
第二个参数(右上角)
x -> 85%
y-> 0
第三个参数(右下)
x -> 100%
y-> 100%
第四个参数(左下)
x -> 0
y-> 100%
Now, you can achieve that pretty straightforward with clip-path and polygon

In this example we there are 4 parameters.
First parameter ( Top left )
x -> 15%
y -> 0
Second parameter ( Top right )
x -> 85%
y -> 0
Third parameter ( Bottom right )
x -> 100%
y -> 100%
Fourth parameter ( Bottom left )
x -> 0
y -> 100%