【发布时间】:2013-08-30 06:36:28
【问题描述】:
我正在尝试在 CSS3 中重新创建这个形状。
这是我的解决方案:
<span><div id="shape"></div></span>
span {
display: block;
margin-left: 88px;
}
#shape {
width: 160px;
height: 100px;
background: #dcdcdc;
}
#shape:before {
height: 76px;
width: 76px;
top: 20px;
content:"";
position: absolute;
border-radius: 10px;
background-color: #ccc;
left: 60px;
-webkit-transform:rotate(45deg);
}
#shape:after {
height: 76px;
width: 76px;
top: 20px;
content:"";
position: absolute;
border-radius: 10px;
left: 220px;
-webkit-transform:rotate(45deg);
background-color: #ccc;
}
不幸的是,这无法缩放:CodePen demo(我更改了背景颜色以说明我的做法)。垂直缩放很重要。
JavaScript 解决方案也可以。
【问题讨论】:
-
你已经有了你想要的图像。为什么不能只使用它(在去掉灰色背景之后)?您可以为您的页面使用多种尺寸。
-
你想如何扩展它??
-
遗憾的是jQuery不能直接设置伪元素的高度,或者你可以用jQuery来设置。如果你想添加其他 HTML 元素,使用 jQuery 很容易。
-
@TusharGupta 垂直扩展很重要
-
您是否考虑过为此使用 SVG 而不是尝试在纯 CSS 中实现它?创建它并将其正确缩放为 SVG 图像将非常容易。
标签: jquery html css css-shapes