CSS3 Backgrounds

CSS3 contains a couple of new foundation properties, which permit more noteworthy control of the foundation element.

In this part you will figure out how to add different foundation pictures to one element.

You will likewise find out about the accompanying new CSS3 properties:


Browser Support

The numbers in the table indicate the main program form that completely underpins the property.

Numbers pursued by - webkit-, - moz-, or - o-indicate the main form that worked with a prefix.

Property
background-image
(with numerous backgrounds)
4.0 12.0 9.0 3.6 3.1 11.5
background-size 4.0
1.0 - webkit-
12.0 9.0 4.0
3.6 - moz-
4.1
3.0 - webkit-
10.5
10.0 - o-
background-origin 1.0 12.0 9.0 4.0 3.0 10.5
background-clip 4.0 12.0 9.0 4.0 3.0 10.5

CSS3 Multiple Backgrounds

CSS3 enables you to include different foundation pictures for a component, through the background-image property.

Multiple foundation pictures are indicated utilizing a comma-isolated rundown of qualities for the foundation picture property.

The following precedent has two foundation pictures, the primary picture is a blossom (adjusted to the base and right) and the second picture is a paper foundation (adjusted to the upper left corner):

Example

#example1 {
    foundation picture: url(img_flo.jpg), url(paper.gif);
    foundation position: right base, left top;
    foundation rehash: no-rehash, repeat;
}
Try it yourself »

Multiple foundation pictures can be determined utilizing either the person foundation properties (as above) or the background shorthand property.

The following precedent uses the background shorthand property (same outcome as precedent above):

Example

#example1 {
    foundation: url(img_flo.jpg) right base no-rehash, url(paper.gif) left best repeat;
}
Try it yourself »

CSS3 Background Size

The CSS3 background-size property enables you to indicate the measure of foundation images.

Before CSS3, the measure of a foundation picture was the genuine size of the picture. CSS3 enables us to re-use foundation pictures in various contexts.

The size can be indicated in lengths, rates, or by utilizing one of the two watchwords: contain or cover.

The following model resizes a foundation picture to a lot littler than the first picture (utilizing pixels):

Original foundation image:

Pills and Potions

People will love you and bolster you when it's beneficial.

Resized foundation image:

Modern day maharaja

Without request, nothing exists. Without disorder, nothing evolves.

Here is the code:

Example

#div1 {
    foundation: url(img_flo.jpgwer.jpg);
    foundation estimate: 100px 80px;
    foundation rehash: no-repeat;
}
Try it yourself »

The two other conceivable qualities for background-size are contain what's more, cover.

The contain watchword scales the foundation picture to be as huge as could reasonably be expected (be that as it may, the two its width and its stature must fit inside the substance region). Thusly, contingent upon the extents of the foundation picture and the foundation situating region, there might be a few territories of the foundation which are not secured by the foundation image.

The cover catchphrase scales the foundation picture with the goal that the substance territory is totally secured by the foundation picture (the two its width and tallness are equivalent to or surpass the substance region). All things considered, a few sections of the foundation picture may not be unmistakable out of sight situating area.

The following model shows the utilization of contain and cover:

Example

#div1 {
    foundation: url(img_flo.jpgwer.jpg);
    foundation estimate: contain;
    foundation rehash: no-repeat;
}
#div2 {
    foundation: url(img_flo.jpgwer.jpg);
    foundation estimate: cover;
    foundation rehash: no-repeat;
}
Try it yourself »

Define Sizes of Multiple Background Images

The background-size property additionally acknowledges various qualities for foundation estimate (utilizing a comma-isolated rundown), when working with various backgrounds.

The following precedent has three foundation pictures indicated, with various foundation estimate an incentive for each image:

Example

#example1 {
    foundation: url(img_flo.jpg) left best no-rehash, url(img_flo.jpg) right base no-rehash, url(paper.gif) left best repeat;
    foundation measure: 50px, 130px, auto;
}
Try it yourself »

CSS3 Backgrounds
WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS3 Backgrounds


CSS3 Backgrounds

CSS3 contains a couple of new foundation properties, which permit more noteworthy control of the foundation element.

In this part you will figure out how to add different foundation pictures to one element.

You will likewise find out about the accompanying new CSS3 properties:

  • background-size
  • background-origin
  • background-clip

Browser Support

The numbers in the table indicate the main program form that completely underpins the property.

Numbers pursued by - webkit-, - moz-, or - o-indicate the main form that worked with a prefix.

Property
background-image
(with numerous backgrounds)
4.0 12.0 9.0 3.6 3.1 11.5
background-size 4.0
1.0 - webkit-
12.0 9.0 4.0
3.6 - moz-
4.1
3.0 - webkit-
10.5
10.0 - o-
background-origin 1.0 12.0 9.0 4.0 3.0 10.5
background-clip 4.0 12.0 9.0 4.0 3.0 10.5

CSS3 Multiple Backgrounds

CSS3 enables you to include different foundation pictures for a component, through the background-image property.

Multiple foundation pictures are indicated utilizing a comma-isolated rundown of qualities for the foundation picture property.

The following precedent has two foundation pictures, the primary picture is a blossom (adjusted to the base and right) and the second picture is a paper foundation (adjusted to the upper left corner):

Example

#example1 {
    foundation picture: url(img_flo.jpg), url(paper.gif);
    foundation position: right base, left top;
    foundation rehash: no-rehash, repeat;
}
Try it yourself »

Multiple foundation pictures can be determined utilizing either the person foundation properties (as above) or the background shorthand property.

The following precedent uses the background shorthand property (same outcome as precedent above):

Example

#example1 {
    foundation: url(img_flo.jpg) right base no-rehash, url(paper.gif) left best repeat;
}
Try it yourself »

CSS3 Background Size

The CSS3 background-size property enables you to indicate the measure of foundation images.

Before CSS3, the measure of a foundation picture was the genuine size of the picture. CSS3 enables us to re-use foundation pictures in various contexts.

The size can be indicated in lengths, rates, or by utilizing one of the two watchwords: contain or cover.

The following model resizes a foundation picture to a lot littler than the first picture (utilizing pixels):

Original foundation image:

Pills and Potions

People will love you and bolster you when it's beneficial.

Resized foundation image:

Modern day maharaja

Without request, nothing exists. Without disorder, nothing evolves.

Here is the code:

Example

#div1 {
    foundation: url(img_flo.jpgwer.jpg);
    foundation estimate: 100px 80px;
    foundation rehash: no-repeat;
}
Try it yourself »

The two other conceivable qualities for background-size are contain what's more, cover.

The contain watchword scales the foundation picture to be as huge as could reasonably be expected (be that as it may, the two its width and its stature must fit inside the substance region). Thusly, contingent upon the extents of the foundation picture and the foundation situating region, there might be a few territories of the foundation which are not secured by the foundation image.

The cover catchphrase scales the foundation picture with the goal that the substance territory is totally secured by the foundation picture (the two its width and tallness are equivalent to or surpass the substance region). All things considered, a few sections of the foundation picture may not be unmistakable out of sight situating area.

The following model shows the utilization of contain and cover:

Example

#div1 {
    foundation: url(img_flo.jpgwer.jpg);
    foundation estimate: contain;
    foundation rehash: no-repeat;
}
#div2 {
    foundation: url(img_flo.jpgwer.jpg);
    foundation estimate: cover;
    foundation rehash: no-repeat;
}
Try it yourself »

Define Sizes of Multiple Background Images

The background-size property additionally acknowledges various qualities for foundation estimate (utilizing a comma-isolated rundown), when working with various backgrounds.

The following precedent has three foundation pictures indicated, with various foundation estimate an incentive for each image:

Example

#example1 {
    foundation: url(img_flo.jpg) left best no-rehash, url(img_flo.jpg) right base no-rehash, url(paper.gif) left best repeat;
    foundation measure: 50px, 130px, auto;
}
Try it yourself »

Full Size Background Image

Now we need to have a foundation picture on a site that covers the whole program window at all times.

The prerequisites are as follows:

  • Fill the whole page with the picture (no white space)
  • Scale picture as needed
  • Center picture on page
  • Do not cause scrollbars

The following model tells the best way to do it; Use the html component (the html component is dependably at any rate the tallness of the program window). At that point set a settled and fixated foundation on it. At that point alter its size with the foundation measure property:

Example

html {
    foundation: url(img_flo.jpgwer.jpg) no-rehash focus settled;
    foundation measure: cover;
}
Try it yourself »

CSS3 foundation source Property

The CSS3 background-origin property indicates where the foundation picture is positioned.

The property takes three diverse values:

  • border-box - the foundation picture begins from the upper left corner of the border
  • padding-box - (default) the foundation picture begins from the upper left corner of the cushioning edge
  • content-box - the foundation picture begins from the upper left corner of the content

The following model outlines the background-origin property:

Example

#example1 {
    fringe: 10px strong black;
    cushioning: 35px;
    foundation: url(img_flo.jpg);
    foundation rehash: no-repeat;
    foundation birthplace: content-box;
}
Try it yourself »

CSS3 foundation cut Property

The CSS3 background-clip property indicates the artistic creation region of the background.

The property takes three diverse values:

  • border-box - (default) the foundation is painted to the outside edge of the border
  • padding-box - the foundation is painted to the outside edge of the padding
  • content-box - the foundation is painted inside the substance box

The following precedent delineates the background-clip property:

Example

#example1 {
    outskirt: 10px specked black;
    cushioning: 35px;
    foundation: yellow;
    foundation cut: content-box;
}