是否可以在 CSS 中创建一个如下所示的按钮:
当然我不是说使用图像作为背景,我可以很容易地做到这一点。我说的是 webkit 类型的解决方案。
简短的回答是肯定的,可以做到。我继续尝试。
这些是我采取的步骤:
box-shadow
在外部和插图中添加 s,以尽可能接近地复制位图。请注意,我只使用黑色和白色(具有不同的 alpha 值)作为框阴影。这样,您只需更改background-color
.:before
和:after
pseudo 元素将它们包含在您的 css 中。生成的图像看起来像这样(不准确,但我认为非常接近):
然后我通过选择“复制 css 属性”并手动添加 :before 和 :after 元素并进行一些微调,将绘图转换为 css。这是我想出的(无前缀的)css:
.button {
display: inline-block;
color: #fff;
text-shadow: 0 0 2px rgba(0,0,0,.3);
font-family: sans-serif;
box-shadow:
inset 0 0 2px 0 rgba(255,255,255,.4),
inset 0 0 3px 0 rgba(0,0,0,.4),
inset 0 0 3px 5px rgba(0,0,0,.05),
2px 2px 4px 0 rgba(0,0,0,.25);
border-radius: 4px;
padding: 8px 16px;;
font-size: 12px;
line-height: 14px;
position: relative;
}
.button.red { background: #EA3D33; }
.button.green { background: #7ED321; }
.button.blue { background: #4A90E2; }
.button:before, .button:after {
content: '';
display: block;
position: absolute;
left: 2px;
right: 2px;
height: 3px;
}
.button:before {
top: 0;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
background: rgba(255,255,255,.6);
box-shadow: 0 1px 2px 0 rgba(255,255,255,.6);
}
.button:after {
bottom: 0;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
background: rgba(0,0,0,.15);
box-shadow: 0 -1px 2px 0 rgba(0,0,0,.15);
}
和一个小提琴来演示:http: //jsfiddle.net/pn4qk3wL/