How to stretch background image of a table cell with CSS?

被刻印的时光 ゝ 提交于 2019-12-04 22:28:04

问题


How can I stretch background image of a table cell with CSS? I have Googled it with no results.

When you set background image of a cell and the background size is smaller than the cell, then it will be repeated.

How can I force this background to stretch the entire table cell instead?


回答1:


You can't stretch a background image.

If you want to stretch an image, you have to put it in an img tag. You can use absolute positioning to put content on top of the image.




回答2:


It is possible to stretch a background image using the background-size CSS property.

Examples:

body { background-size: 100% auto } /* Stretches image to full horiz. width */
body { background-size: 50% 50% } /* Stretches image to half of available
width and height - WARNING: aspect ratio not maintained */

body { background-size: cover } /* Ensures that image covers full area */
body { background-size: contain } /* Ensures that image is completely visible */

All major current browsers support the feature:

  • IE since 9.0
  • Chrome since 3.0
  • Firefox since 4.0
  • Opera since 10.0
  • Safari since 4.1



回答3:


It is possible.

NOTE: This is using CSS3 and will not be supported by inferior browsers.

If you set your cell with this styling it should solve your problem. It will also allow for collapsible tables too because you're using %.

background-image: url('XXX');
background-repeat: no-repeat;
background-size: 100% 100%;


来源:https://stackoverflow.com/questions/3388360/how-to-stretch-background-image-of-a-table-cell-with-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!