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

Susan Sarandon
Release: 2024-11-05 06:12:02
Original
245 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template