Home  >  Article  >  Web Front-end  >  How to Stretch a Background Image to Fill a TD Cell with CSS?

How to Stretch a Background Image to Fill a TD Cell with CSS?

Susan Sarandon
Susan SarandonOriginal
2024-11-05 06:12:02242browse

How to Stretch a Background Image to Fill a TD Cell with CSS?

Covering the TD Cell with an Image Stretch

Issue: Enhance a webpage by stretching a background image to fill the entirety of a table cell () using CSS.

CSS Fragment:

<code class="css"><style>
.style1 {
    background-image: url('http://localhost/msite/images/12.PNG');
    background-repeat: no-repeat;
    background-position: left center;
}
</style></code>

Objective: Employ CSS to extend the background image to encompass the entire TD cell, achieving a "stretched" effect.

Solution:

<code class="css">.style1 {
    background: url(images/bg.jpg) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}</code>

Compatibility:

  • Safari 3
  • Chrome
  • IE 9
  • Opera 10
  • Firefox 3.6

Additional Option for IE:

<code class="css">filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='.myBackground.jpg', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='myBackground.jpg', sizingMethod='scale')";
zoom: 1;</code>

Acknowledgement:

Credits go to Chris Coyier for the insightful article found at: http://css-tricks.com/perfect-full-page-background-image/

The above is the detailed content of How to Stretch a Background Image to Fill a TD Cell with CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn