简体   繁体   中英

image without initial src doesn't display css background-image: url(“image.png”);

I have a table with the same small image on every row.

Seen as the table has thousands of rows, I'd like to not set the src , width and height of the image in html and instead do this with css using a class.

.clbtn {
width: 18px; 
height: 18px;
background-image: url("image.png");
}

Doing this would decrease the initial size of the page.

However while this work fine in chrome it doesn't in firefox. Is there another way around this than a $(document).ready(function(){ $(".clbtn").attr("src", "image.png");}); after the table?

That's because how the browser handle images with missing src attrs. Perhaps the most sensate thing to do if you really need to do this this way, is to src all the img with a 1x1 transparent gif.

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