CSS Background-size Property - Dofactory
Có thể bạn quan tâm
- SQL
SQL Tutorial SQL Reference Connection Strings
- .NET
C# Design Patterns C# Coding Standards C# Code Examples Visual Studio Shortcut Keys
- HTML
HTML Tutorial HTML Reference
- CSS
CSS Tutorial CSS Reference
- JavaScript
JavaScript Tutorial JavaScript Design Patterns
- SQL
- .NET
- HTML
- CSS
- JavaScript
Select tutorial
Select tutorial
Select tutorial
Select tutorial
Select tutorial
Back to CSS Select Tutorial - HTML Tutorial
- HTML Reference
- CSS Tutorial
- CSS Reference
- SQL Tutorial
- SQL Reference
- JavaScript Tutorial
- JavaScript Patterns
- C# Design Patterns
- C# Coding Standards
- Connection Strings
- Visual Studio Shortcuts
The background-size property sets the background image size.
It accepts two values: width and height.
Example
#
A resized background image using background-size.
<style> .withbg { background-image: url("/img/css/cardplayers.jpg"); background-repeat: no-repeat; background-size: 200px 150px; height: 200px; } </style> <div class="withbg"></div> Try it live Tip: It's recommended to use the exact image size instead of resizing with CSS to reduce the page loading time and resources used.Using background-size
#
background-size accepts 2 values: the width and the height.
Values are set as length units, such as, px, %, em, and others.
If only one value is provided, it will be used as both width and height.
Multiple background sizes can also be specified for multiple images.
background-repeat borderSyntax
#
background-size: auto | length | cover | contain | initial | inherit;Values
#
| Value | Description |
|---|---|
| auto | Default. Displays background image original size. |
| length | Sets width (first value) and height (second value) of background image. If the second value is not given, it will be set to auto. |
| percentage | Sets width (first value) and height (second value) of background image in percent. If the second value is not given, it will be set to auto. |
| cover | Stretch or crop background image to cover the entire container. |
| contain | Resize background image to make it fully visible. |
| initial | Sets the value to its default value. |
| inherit | Inherits the value from its parent element. |
More Examples
#
Click the buttons to see the different background-size values.
auto length: 200px 180px percentage: 65% cover contain initial inherit
<style> .bg-example { background-image: url("/img/css/cardplayers.jpg"); background-repeat: no-repeat; background-size: contain; height: 300px; } </style> <div class="bg-example"></div> Try it liveBrowser support
#
This table shows when background-size support started for each browser.
Chrome | 4.0 | Jan 2010 |
Firefox | 4.0 | Mar 2011 |
IE/Edge | 9.0 | Mar 2011 |
Opera | 10.5 | Mar 2010 |
Safari | 3.0 | Jun 2007 |
You may also like
#
- Our CSS background-repeat Property Reference
- Our CSS background-position Property Reference
- Our HTML Background Images Tutorial
Jack Poorte Last updated on Sep 30, 2023 Earn income with your CSS skills Sign up and we'll send you the best freelance opportunities straight to your inbox. We're building the largest freelancing marketplace for people like you. Send Me Opportunities By adding your name & email you agree to our terms, privacy and cookie policies. Feedback Guides - CSS Tutorial
- CSS Selectors
- CSS Borders
- CSS Flex
- CSS Grid
- CSS Tables
- CSS Length
- CSS Fonts
- CSS Animation
- CSS Hover
- CSS Images
- CSS Comments
- CSS background-size
- Example
- Using
- Syntax
- Values
- More Examples
- Browser support
- You may also like
Từ khóa » Html Table Background Image Auto Resize
-
Html - Resize Table Background Image Without Losing Aspect Ratio ...
-
Resizing Background Images With Background-size - CSS
-
Html Background Image Auto Resize Code Example - Code Grepper
-
CSS Background-size Property - W3Schools
-
Responsive Web Design Images - W3Schools
-
How To Specify Table Background Image Width And Height - MSDN
-
Learn The Examples Of HTML Table Background - EduCBA
-
HTML Table Background
-
How To Auto-Resize The Image To Fit An HTML Container - W3docs
-
A Guide To HTML Background Images In Email - Email On Acid
-
Auto Resize Image In Table Html
-
How Do I Make The Background Image Stretch To Fit The Table Cell?
-
How To Create A Responsive Background Image With CSS [Guide]
-
How To Auto Resize Css Background Image?
Chrome
Firefox
IE/Edge
Opera
Safari