我有这个175x175的背景图片,但我试图用它制作一张“CD”封面。在下面的代码(jsFiddle available)中,您将看到它没有调整大小,只是“裁剪”。我该如何解决这个问题?
HTML:
<div class="cd"><div class="hole"></div></div>
<p>I want the image above to be resized to 75x75... but it's not</p>
<img src="http://userserve-ak.last.fm/serve/126/23679395.jpg" alt="Test" />
<p>Actual image size above.</p>
CSS:
.cd {
-moz-border-radius: 63px;
-webkit-border-radius: 63px;
border-radius: 63px;
background-image: url('http://userserve-ak.last.fm/serve/126/23679395.jpg');
width: 75px;
height: 75px;
position: relative;
border:1px solid #A1A1A1;
}
.cd .hole {
width: 20px;
height: 20px;
position: absolute;
background-color: #ddd;
border:1px solid #A1A1A1;
left: 28px;
top: 28px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;
}
答案 0 :(得分:6)
使用background-size CSS属性:
background-size: 75px 75px;
可替换地:
background-size: 100% 100%;
还有简写 background 属性:
background: url('http://userserve-ak.last.fm/serve/126/23679395.jpg') 100% 100%;
答案 1 :(得分:2)
像这里使用背景大小:
.cd {
-moz-border-radius: 63px;
-webkit-border-radius: 63px;
border-radius: 63px;
background-image: url('http://userserve-ak.last.fm/serve/126/23679395.jpg');
background-size: 75px;
width: 75px;
height: 75px;
position: relative;
border:1px solid #A1A1A1;
}
答案 2 :(得分:1)
使用background-size:覆盖它将填充容器的任何大小。
.cd {
-moz-border-radius: 63px;
-webkit-border-radius: 63px;
border-radius: 63px;
background-image: url('http://userserve-ak.last.fm/serve/126/23679395.jpg');
background-size:cover;/*Add This*/
-webkit-background-size: cover;/*Add This for webkit*/
-moz-background-size: cover;/*Add This for mozilla*/
-o-background-size: cover;/*Add This for opera*/
width: 75px;
height: 75px;
position: relative;
border:1px solid #A1A1A1;
}