CSS - 背景大小不适用于 jpg 扩展

标签 css background-size

.baner {
    background-image: url('ban.jpg');
    background-size: cover;
    background-repeat: no-repeat;
    position: fixed;
    width: 100%;
    height: 35%;
    top: 60px;
}

不会覆盖这个背景,但是当我做 png 图像时它起作用了,我不明白为什么:

.baner {
    background-image: url('ban.png');
    background-size: cover;
    background-repeat: no-repeat;
    position: fixed;
    width: 100%;
    height: 35%;
    top: 60px;
}

最佳答案

对我来说效果很好,也许你没有将图像保存为 .jpg 或其他...

div.one {
    width:100px;
    height:100px;
    background-image:url(http://placekitten.com.s3.amazonaws.com/homepage-samples/408/287.jpg);
    background-position:center;
    background-repeat:no-repeat;
    background-size:cover;
}
div.two {
    width:500px;
    height:500px;
    background-image:url(http://placekitten.com.s3.amazonaws.com/homepage-samples/408/287.jpg);
    background-position:center;
    background-repeat:no-repeat;
    background-size:cover;
}
<div class="one">
    
</div>
<div class="two">
    
</div>

关于CSS - 背景大小不适用于 jpg 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28250730/

相关文章:

jquery - 过滤掉包含多个 css 类的 tr

html - 如何使用 Bootstrap3 将两个图像居中

css - 背景大小覆盖淡入淡出过渡没有大小过渡

css - 需要空 div 的背景图像以在所有屏幕尺寸上以适当的比例显示

css - 全屏无限滚动背景

用于在 react 中为一行 antd 表着色的 CSS

html - 子菜单在 Mac OS 10.6 上的 Chrome、Safari 和 Firefox 中消失

css - 如何在固定高度的 div 中保持漂亮的 Logo ?

CSS 背景大小 : cover + background-attachment: fixed clipping background images

css - 如何为 JSTree 获取兼容 IE8 的 css 主题?