html - 在 css 中倾斜正方形的垂直线?

标签 html css

我的页面中有一些方形 div,我将它们用作按钮。如何在不旋转整个正方形的情况下使垂直线有点倾斜?

我想让一个正方形看起来像图 1(绿色)而不是图 2(红色)

这可以通过 css 实现还是应该使用图像?

enter image description here

html:
<div id="square"></div>

css:
 #square {
 width:50px;
 height:50px;
 display:block;
 background-color:red;
 overflow:hidden
 }

http://jsfiddle.net/gmrq1ac4/

最佳答案

使用 CSS3 变换:倾斜

#square {
    -ms-transform: skew(30deg); /* IE 9 */
    -webkit-transform: skew(30deg); /* Chrome, Safari, Opera */
    transform: skew(30deg); /* Standard syntax */
    transform-origin: bottom left; /* Prevent the bottom from shifting */
}

这是一个 example

关于html - 在 css 中倾斜正方形的垂直线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25437986/

相关文章:

html - 我的按钮和链接的悬停功能不起作用

html - 如何调整彼此下的div和链接

javascript - 如何更改下拉菜单以使用触摸屏?

css - 将图像包装在灯箱的 <a> 标记中时出错

jQuery 使用 Data 属性设置 Class 的 CSS 样式

html - CSS - 在环绕的跨度左侧填充

html - 使用 flexbox 时,<div> 和 <span> 之间是否存在功能差异

javascript - 简单但丢失 : Embeding Javascript into HTML

CSS - 如何升级 Unicode 箭头?

javascript - JQuery 使用 mouseX 百分比隐藏/显示