内联图像相当于CSS后台附件属性?

时间:2014-05-04 10:30:01

标签: html css

我网站的主页上有一个用这个CSS实现的横幅图片。使用媒体查询,背景图像设置为在较小的屏幕上滚动:

#banner {
    background: url("../images/banner1.jpg") no-repeat fixed left 13em / 100% auto rgba(0, 0, 0, 0);
    height: 47em;
    overflow: hidden;
    width: 100%;
}

/* Mobile */
@media screen and (max-width: 767px) {

#banner {
    height: 27em;
    background-attachment: scroll;
    background-position: left 7em;
    }

}

我想将其设为内嵌图像,因此可以通过我的CMS轻松更新。设计师说它必须是一个CSS背景图像,用于应用背景附件属性。

我怀疑CSS位置属性是否可以在内嵌图像上使用以获得相同的效果?或者这是图像是CSS背景而不是内联的情况?

2 个答案:

答案 0 :(得分:1)

虽然最好使用css,但您也可以使用responsive image。此外,您可以使用单独的图像与媒体查询,例如,为两个不同的设备创建两个不同大小的图像,并保持一个隐藏,一个可见,如下所示:

// Common rules for both images
.banner {
    //...
}

#bannerBig {
    display:block;
}

#bannerSmall {
    display:none;
}

/* Mobile */
@media screen and (max-width: 767px) {

    #bannerBig {
        display:none;
    }

    #bannerSmall {
        display:block;
    }
}

图片:

<img class='banner' id='bannerBig' src='' />
<img class='banner' id='bannerSmall' src='' />

同时查看another solution的此链接。最好与你的设计师讨论你应该使用哪一个。

答案 1 :(得分:0)

是的,您可以将图像嵌入为内嵌图像,使用此工具将图像转换为base64格式图像

http://webcodertools.com/imagetobase64converter/Create

background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAABLCAYAAABZeprtAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAA2oSURBVHhe7ZzPq11XFced+RdI58VB5y3SuZl0HDoVRCjoQEGQQAdiC0JpnEQqktYKsVBMFCWjRqMY0EgKqUZtIRJjbalEK02KxYaKucf3Obnf1+9bb+1zzn33vry8e9cHFu/es9f+cdZe3332Offe94muKIq1p4ReFBtACb0oNoASelFsACX0otgASuhFsQE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