是否可以将div样式设置为梯形? [英] Is it possible to style a div to be trapezoidal?

查看:927
本文介绍了是否可以将div样式设置为梯形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有可能偏斜,但我没有看到以特定的程度扭曲每个角落的方法。

I know it's possible to skew but I don't see a way to skew each corner with a particular degree.

这是我正在处理的项目: http://map.ucf.edu/

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.

我知道可以创建一个 CSS trapazoid ,但是这是使用没有内容的边框。最终结果还需要一些圆角。

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.

编辑:
Zoltan Toth的解决方案我能够实现这个:演示

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; }


推荐答案

div {
    width: 200px;
    height: 100px;
    background: #ddd;
    margin: 20px 150px;
    position: relative
}

div:before {
    content: '';
    line-height: 0;
    font-size: 0;
    width: 0;
    height: 0;
    border-top: 50px solid transparent;
    border-bottom: 50px solid #ddd;
    border-left: 50px solid transparent;
    border-right: 50px solid #ddd;
    position: absolute;
    top: 0;
    left: -99px;
}

div:after {
    content: '';
    line-height: 0;
    font-size: 0;
    width: 0;
    height: 0;
    border-top: 50px solid transparent;
    border-bottom: 50px solid #ddd;
    border-left: 50px solid #ddd;
    border-right: 50px solid transparent;
    position: absolute;
    top: 0;
    right: -99px;
}

<div>Hello</div>

<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam cursus ex quis enim posuere auctor.</div>

这篇关于是否可以将div样式设置为梯形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆