【发布时间】:2015-02-03 09:35:07
【问题描述】:
有没有办法用 css 设置独立于背景的一般大小的图像大小?
我用下面的代码设置了背景的大小,所以渐变和图片的宽度都是30px。
background(url("../images/icons/double_arrow_37px.svg"), linear-gradient(to top bottom, rgb(171, 129, 85), rgb(148, 112, 74)));
background-size: 30px 37px;
我需要将图像的宽度设置为 30px,将渐变设置为按钮宽度的 100%。
我已经知道创建具有正确尺寸的额外图像的解决方法,但也许有更聪明的 css 方法?
完整示例:
body {
background-color: #000;
}
.button-custom {
color: #fff;
font-family: $font-centennial;
background-image: url("http://metk.de/kunden/*/double_arrow_37px.svg");
background-size: 30px 37px;
background-position: center left;
background-repeat: no-repeat;
margin-top: 70px;
padding: 15px 45px;
border-radius: 0;
border: 0;
text-transform: uppercase;
overflow: hidden;
}
.button-custom.bronze {
background-color: #ab8155;
}
.button-custom.bronze:hover {
background: url("http://metk.de/kunden/*/double_arrow_37px.svg"), -moz-linear-gradient(bottom, #ab8155, #94704a);
background: url("http://metk.de/kunden/*/double_arrow_37px.svg"), -webkit-linear-gradient(bottom, #ab8155, #94704a);
background: url("http://metk.de/kunden/*/double_arrow_37px.svg"), linear-gradient(to top bottom, #ab8155, #94704a);
background-position: center left;
background-size: 30px 37px;
background-position: center left;
background-repeat: no-repeat;
color: #fff;
}
<a href="#" class="button-custom bronze">Contact</a>
【问题讨论】:
-
您还想为背景颜色/渐变指定大小??还是只是图片??
-
您能否为此提供一些标记?老实说,所有这些关于按钮和图像的讨论都让人很不清楚。
-
我更新了问题。我想设置图像的大小,但渐变应该有全宽。当您悬停链接时,您会明白我的意思;)。
标签: css background-image linear-gradients