简体   繁体   中英

CSS IE7 Background

I have the CSS:

.dot-preview {
    background: url("../images/dot.png") no-repeat scroll 0 0 transparent;
}

but IE 7/8/9 don't show the image.

Called from:

<img class="dot-preview">

What is wrong with my code? It is IE bug?

Assigning background to empty image tag makes very little sense. Use <div> element instead and the key is to give it proper width and height:

<div class="dot-preview"></div>

And in the CSS:

.dot-preview {
    width: 300px;
    height: 300px;
    /* ... */
}

Put the correct image width and height and it should work fine.

Try This

HTML

<img class="dot-preview" />

css

.dot-preview {
    background:#000 url("../images/dot.png") repeat scroll 0 0;
}

Set a height and width to your image.

.dot-preview {
    background: url("../images/dot.png") no-repeat scroll 0 0 transparent;
    height: 100px;
    width: 100px;
}

you might also want to have a transparent 2x2px image in the src of your image, or else IE will show a "not found" icon

EDIT:

in IE, transparent placeholders should be 2x2px wide. as they create a visual bug if they are 1px wide

Do the following:

HTML

<img class="dot-preview" />

CSS

.dot-preview {
    background: url("../images/dot.png") repeat scroll 0 0 transparent;
    display:block;
    width: 800px;
    height: 600px;
}

You can change the width and height as you like

.dot-preview {
    background-image: url("../images/dot.png");
    background-repeat: no-repeat;
    display:block;
    width: 800px;
    height: 600px;
}

Basically you should have display block for the class you want to have background-image, or you can have this whole thing in div with class .dot-preview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM