Myanmar Coder Guide

Course Outline from w3school.com

Tuesday, April 27, 2021

CSS background-size Property

Example

နောက်ခံပုံရဲ့အရွယ်အစားကို "auto" နဲ့ pixels တွေသတ်မှတ်နိုင်ပါသည်။

  1. #example1{
  2.     background-img: url("mountain.jpg");
  3.     background-repeat: on-repeat;
  4.     background-size: auto;
  5. }
  6. #example2{
  7.     background-img: url("mountain.jpg");
  8.     background-repeat: on-repeat;
  9.     background-size: 300px 100px;
  10. }
Try it Yourself »

Definition and Usage

Background-size property ကနောက်ခံပုံတွေရဲ့အရွယ်အစားကိုသတ်မှတ်ပါတယ်။ သင်သုံးနိုင်သောကွဲပြားခြားနားသော syntaxes ၄ ခုရှိသည်။ ("auto", "cover" နှင့် "contain")၊ one-value syntax (ပုံ၏အကျယ်ကိုသတ်မှတ်သည် (အမြင့်သည် "auto")၊ two-value syntax (ပထမတန်ဖိုး : ပုံအကျယ်၊ ဒုတိယတန်ဖိုး : အမြင့်)သတ်မှတ်နိုင်သည်။

Default value: auto
Inherited: no
Animatable: yes
Version: CSS3
JavaScript syntax: object.style.backgroundSize="60px 120px"

Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Numbers followed by -webkit-, -moz-, or -o- specify the first version that worked with a prefix.

Property
background-size  4.0
1.0 -webkit-
9.0 4.0
3.6 -moz-
4.1
3.0 -webkit-
10.5
10.0 -o-

CSS Syntax

background-size: auto|length|cover|contain|initial|inherit;

Property Values

Value Description
auto Default value. The background image is displayed in its original size
length Sets the width and height of the background image. The first value sets the width, the second value sets the height. If only one value is given, the second is set to "auto".
percentage Sets the width and height of the background image in percent of the parent element. The first value sets the width, the second value sets the height. If only one value is given, the second is set to "auto"
cover Resize the background image to cover the entire container, even if it has to stretch the image or cut a little bit off one of the edges
contain Resize the background image to make sure the image is fully visible
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

More Examples

Example

နောက်ခံပုံ၏ရာခိုင်နှုန်းကိုသတ်မှတ်ပါ။

  1. #example1{
  2.     background-img: url("mountain.jpg");
  3.     background-repeat: on-repeat;
  4.     background-size: 100% 100%;
  5. }
  6. #example2{
  7.     background-img: url("mountain.jpg");
  8.     background-repeat: on-repeat;
  9.     background-size: 75% 50%;
  10. }
Try it Yourself »

Example

နောက်ခံပုံရဲ့အရွယ်အစားကို "cover" နဲ့သတ်မှတ်ပါ။

  1. #example1{
  2.     background-img: url("mountain.jpg");
  3.     background-repeat: on-repeat;
  4.     background-size: cover;
  5. }
Try it Yourself »

Example

နောက်ခံပုံရဲ့အရွယ်အစားကို "contain" နဲ့သတ်မှတ်ပါ။

  1. #example1{
  2.     background-img: url("mountain.jpg");
  3.     background-repeat: on-repeat;
  4.     background-size: contain;
  5. }
Try it Yourself »

Example

နောက်ခံပုံရဲ့အရွယ်အစားကို "cover" နဲ့သတ်မှတ်ပါ။

  1. #example1{
  2.     background-img: url("mountain.jpg");
  3.     background-repeat: on-repeat;
  4.     background-size: contain,cover;
  5. }
Try it Yourself »

Example

  1. #example1{
  2.     background-img: url("photographer.jpg"); /* The image used */
  3.     background-color: #cccccc; /* Used if the image is unavailable */
  4.     hight: 500px; /* You must set a specified height */
  5.     baackground-position: center; /* Center the image */
  6.     baackground-repeat: no-repeat; /* Do not repeat the image */
  7.     background-size: cover; /* Resize the background image to cover the entire container */
  8. }
Try it Yourself »

No comments:

Post a Comment