css - 无法使用 CSS 限制图像大小

标签 css background-image

我一直在努力让这张背景图片发挥作用,这让我有点抓狂。似乎无法找出正确的编码。

现在,pdficon 非常大,根本不在它应该“包含”在其中的容器中。我只是不确定如何正确定位背景图片。

HTML代码(自定义代码框):

<a href="<url>" style="text-decoration:none;font-family:arial;font-color:black;">
<div id="main">
<div id="first">
</div>
<div id="second">
<p>TEXT
</p>
</div>
</div>
</a>

CSS:

div#first {
    background-image: url('pdfIcon.png');
    position:absolute;
    width:100%;
    height:100%;
    overflow:hidden;
    background-repeat: no-repeat;
    opacity:0.2;
    -moz-background-size: 100% 100%;           /* Gecko 1.9.2 (Firefox 3.6) */
     -o-background-size: 100% 100%;           /* Opera 9.5 */
    -webkit-background-size: 100% 100%;           /* Safari 3.0 */
    background-size: 100% 100%;           /* Gecko 2.0 (Firefox 4.0) and other CSS3-compliant browsers */
    -moz-border-image: url('pdfIcon.png') 0;
}
div#second{
width:100%;
height:100%;
position:relative;
top: 0;
left:0;
}

这是 JSFiddle

最佳答案

背景大小“cover”属性可能就是您要找的:

background-size: cover

关于css - 无法使用 CSS 限制图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28149897/

相关文章:

iphone - iOS7 的动态类型 CSS 类是什么?

css - 如何使背景图像可访问?

html - 如何只为一页制作 Tumblr 背景图片?

Jquery在没有类名的情况下向div添加一个类

javascript - console.log 不解析 css 样式

css - firefox 中 css 保留 id 名称的限制

html - ASP :Menu children stays visible

html - 你能为 svg "background-image"制作动画吗?

html - 如何在 Bootstrap 容器中将图像显示为背景

jquery - 如何使用 jQuery 访问 "style"属性中的属性?