开发者

div vs image efficiency

开发者 https://www.devze.com 2023-01-11 23:00 出处:网络
What is a better solution in terms of size (page loading speed etc.): I need to have many (up to a couple hundred) small, colored boxes (about 30x30 pixels or so) shown on a single websi开发者_Python

What is a better solution in terms of size (page loading speed etc.):

I need to have many (up to a couple hundred) small, colored boxes (about 30x30 pixels or so) shown on a single websi开发者_Python百科te. Should I

  • Make each box a div with a colored background?
  • Make each box an image loaded onto the page?

There are only a few (less than 6 colors) and these are being displayed in a table.

Thanks


Colored background would be way better for many reasons:

  1. the html tag will be smaller

    <div class='xyz'></div> compared to <img src='images/yourfile.jpg'>

  2. background-color has no limit (well 17millions colors) while creating image will be long if you ever need more

Edit: After reading back, if you are to put Colored Div into a table, would not it be easier to just put <td class='redCell'></td>?

0

精彩评论

暂无评论...
验证码 换一张
取 消