SlideShare a Scribd company logo
❮ Previous Next ❯
CSS Backgrounds
The CSS background properties are used to define the
background effects for elements.
CSS background properties:
• background-color
• background-image
• background-repeat
• background-attachment
• background-position
Background Color
The background-color property specifies the background color of an element.
The background color of a page is set like this:
Example
body {
background-color: lightblue;
}
Try it Yourself »
With CSS, a color is most often specified by:
• a valid color name - like "red"
• a HEX value - like "#ff0000"
• an RGB value - like "rgb(255,0,0)"
Look at CSS Color Values for a complete list of possible color values.
In the example below, the <h1>, <p>, and <div> elements have different
background colors:
Example
h1 {
background-color: green;
}
div {
background-color: lightblue;
}
p {
background-color: yellow;
}
Try it Yourself »
Background Image
The background-image property specifies an image to use as the background of an
element.
By default, the image is repeated so it covers the entire element.
The background image for a page can be set like this:
Example
body {
background-image: url("paper.gif");
}
Try it Yourself »
Below is an example of a bad combination of text and background image. The text
is hardly readable:
Example
body {
background-image: url("bgdesert.jpg");
}
Try it Yourself »
Note: When using a background image, use an image that does not disturb the
text.
Background Image - Repeat Horizontally or
Vertically
By default, the background-image property repeats an image both horizontally and
vertically.
Some images should be repeated only horizontally or vertically, or they will look
strange, like this:
Example
body {
background-image: url("gradient_bg.png");
}
Try it Yourself »
If the image above is repeated only horizontally ( background-repeat:
repeat-x; ), the background will look better:
Example
body {
background-image: url("gradient_bg.png");
background-repeat: repeat-x;
}
Try it Yourself »
Tip: To repeat an image vertically, set background-repeat: repeat-y;
Background Image - Set position and no-repeat
Showing the background image only once is also specified by the background-
repeat property:
Example
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
}
Try it Yourself »
In the example above, the background image is shown in the same place as the
text. We want to change the position of the image, so that it does not disturb the
text too much.
The position of the image is specified by the background-position property:
Example
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
Try it Yourself »
Background Image - Fixed position
To specify that the background image should be fixed (will not scroll with the rest of
the page), use the background-attachment property:
Example
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
background-attachment: fixed;
}
Try it Yourself »
Background - Shorthand property
To shorten the code, it is also possible to specify all the background properties in
one single property. This is called a shorthand property.
The shorthand property for background is background :
Example
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
Try it Yourself »
When using the shorthand property the order of the property values is:
• background-color
• background-image
• background-repeat
• background-attachment
• background-position
Exercise 1 » Exercise 2 » Exercise 3 » Exercise 4 »
Exercise 5 »
❮ Previous Next ❯
It does not matter if one of the property values is missing, as long as the other ones
are in this order.
Test Yourself with Exercises!
All CSS Background Properties
Property Description
background Sets all the background properties in one declaration
background-
attachment
Sets whether a background image is fixed or scrolls
with the rest of the page
background-clip Specifies the painting area of the background
background-color Sets the background color of an element
background-image Sets the background image for an element
background-origin Specifies where the background image(s) is/are
positioned
background-position Sets the starting position of a background image
background-repeat Sets how a background image will be repeated
background-size Specifies the size of the background image(s)
Copyright 1999-2019 by Refsnes Data. All Rights Reserved.

More Related Content

Similar to Background

CSS3 Backgrounds
CSS3 BackgroundsCSS3 Backgrounds
CSS3 Backgrounds
Russ Weakley
 
CSS - Adding Background Images
CSS - Adding Background ImagesCSS - Adding Background Images
CSS - Adding Background Images
Vidya Ananthanarayanan
 
Ict 8 css
Ict 8 cssIct 8 css
Ict 8 css
Christian Reglos
 
CSS
CSSCSS
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
Meenakshi Paul
 
Css+tutorial+in+bangla
Css+tutorial+in+banglaCss+tutorial+in+bangla
Css+tutorial+in+bangla
jessicaemily
 
CssBackgroundImages
CssBackgroundImagesCssBackgroundImages
CssBackgroundImages
Ian Pollock
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
Senthil Kumar
 
Chapter 13: Colors and Backgrounds
Chapter 13: Colors and BackgroundsChapter 13: Colors and Backgrounds
Chapter 13: Colors and Backgrounds
Steve Guinan
 
Kick start @ css
Kick start @ cssKick start @ css
Kick start @ css
Umesh Agarwal
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
Abhishek Kesharwani
 
Introduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxIntroduction to css & its attributes with syntax
Introduction to css & its attributes with syntax
priyadharshini murugan
 
CSS Cascade Style Sheet
CSS Cascade Style SheetCSS Cascade Style Sheet
CSS Cascade Style Sheet
Adeel Rasheed
 
Web technology
Web technologyWeb technology
Web technology
syeda zainab
 
Sensational css how to show off your super sweet
Sensational css  how to show off your super sweet Sensational css  how to show off your super sweet
Sensational css how to show off your super sweet
karenalma
 
CSS for basic learner
CSS for basic learnerCSS for basic learner
CSS for basic learner
Yoeung Vibol
 
TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0
Vladimir Valencia
 
Css introduction
Css  introductionCss  introduction
Css introduction
vishnu murthy
 
Unit - 3 CSS(Cascading Style Sheet).pptx
Unit - 3 CSS(Cascading Style Sheet).pptxUnit - 3 CSS(Cascading Style Sheet).pptx
Unit - 3 CSS(Cascading Style Sheet).pptx
kushwahanitesh592
 
CSS notes
CSS notesCSS notes
CSS notes
Rajendra Prasad
 

Similar to Background (20)

CSS3 Backgrounds
CSS3 BackgroundsCSS3 Backgrounds
CSS3 Backgrounds
 
CSS - Adding Background Images
CSS - Adding Background ImagesCSS - Adding Background Images
CSS - Adding Background Images
 
Ict 8 css
Ict 8 cssIct 8 css
Ict 8 css
 
CSS
CSSCSS
CSS
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
 
Css+tutorial+in+bangla
Css+tutorial+in+banglaCss+tutorial+in+bangla
Css+tutorial+in+bangla
 
CssBackgroundImages
CssBackgroundImagesCssBackgroundImages
CssBackgroundImages
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
Chapter 13: Colors and Backgrounds
Chapter 13: Colors and BackgroundsChapter 13: Colors and Backgrounds
Chapter 13: Colors and Backgrounds
 
Kick start @ css
Kick start @ cssKick start @ css
Kick start @ css
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
Introduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxIntroduction to css & its attributes with syntax
Introduction to css & its attributes with syntax
 
CSS Cascade Style Sheet
CSS Cascade Style SheetCSS Cascade Style Sheet
CSS Cascade Style Sheet
 
Web technology
Web technologyWeb technology
Web technology
 
Sensational css how to show off your super sweet
Sensational css  how to show off your super sweet Sensational css  how to show off your super sweet
Sensational css how to show off your super sweet
 
CSS for basic learner
CSS for basic learnerCSS for basic learner
CSS for basic learner
 
TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0
 
Css introduction
Css  introductionCss  introduction
Css introduction
 
Unit - 3 CSS(Cascading Style Sheet).pptx
Unit - 3 CSS(Cascading Style Sheet).pptxUnit - 3 CSS(Cascading Style Sheet).pptx
Unit - 3 CSS(Cascading Style Sheet).pptx
 
CSS notes
CSS notesCSS notes
CSS notes
 

More from Ankit Dubey

Unit 1 android and it's tools quiz {mad cwipedia}
Unit 1 android and it's tools quiz {mad cwipedia}Unit 1 android and it's tools quiz {mad cwipedia}
Unit 1 android and it's tools quiz {mad cwipedia}
Ankit Dubey
 
Scheduling
Scheduling Scheduling
Scheduling
Ankit Dubey
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
Ankit Dubey
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
Ankit Dubey
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
Ankit Dubey
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
Ankit Dubey
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
Ankit Dubey
 
Ch5 cpu-scheduling
Ch5 cpu-schedulingCh5 cpu-scheduling
Ch5 cpu-scheduling
Ankit Dubey
 
Ch4 threads
Ch4 threadsCh4 threads
Ch4 threads
Ankit Dubey
 
Ch3 processes
Ch3 processesCh3 processes
Ch3 processes
Ankit Dubey
 
Ch2 system structure
Ch2 system structureCh2 system structure
Ch2 system structure
Ankit Dubey
 
Ch1 introduction-to-os
Ch1 introduction-to-osCh1 introduction-to-os
Ch1 introduction-to-os
Ankit Dubey
 
Android i
Android iAndroid i
Android i
Ankit Dubey
 
Mongodb mock test_ii
Mongodb mock test_iiMongodb mock test_ii
Mongodb mock test_ii
Ankit Dubey
 
Android mock test_iii
Android mock test_iiiAndroid mock test_iii
Android mock test_iii
Ankit Dubey
 
Android mock test_ii
Android mock test_iiAndroid mock test_ii
Android mock test_ii
Ankit Dubey
 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06
Ankit Dubey
 
Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05
Ankit Dubey
 
Ajp notes-chapter-04
Ajp notes-chapter-04Ajp notes-chapter-04
Ajp notes-chapter-04
Ankit Dubey
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
Ankit Dubey
 

More from Ankit Dubey (20)

Unit 1 android and it's tools quiz {mad cwipedia}
Unit 1 android and it's tools quiz {mad cwipedia}Unit 1 android and it's tools quiz {mad cwipedia}
Unit 1 android and it's tools quiz {mad cwipedia}
 
Scheduling
Scheduling Scheduling
Scheduling
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Ch5 cpu-scheduling
Ch5 cpu-schedulingCh5 cpu-scheduling
Ch5 cpu-scheduling
 
Ch4 threads
Ch4 threadsCh4 threads
Ch4 threads
 
Ch3 processes
Ch3 processesCh3 processes
Ch3 processes
 
Ch2 system structure
Ch2 system structureCh2 system structure
Ch2 system structure
 
Ch1 introduction-to-os
Ch1 introduction-to-osCh1 introduction-to-os
Ch1 introduction-to-os
 
Android i
Android iAndroid i
Android i
 
Mongodb mock test_ii
Mongodb mock test_iiMongodb mock test_ii
Mongodb mock test_ii
 
Android mock test_iii
Android mock test_iiiAndroid mock test_iii
Android mock test_iii
 
Android mock test_ii
Android mock test_iiAndroid mock test_ii
Android mock test_ii
 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06
 
Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05
 
Ajp notes-chapter-04
Ajp notes-chapter-04Ajp notes-chapter-04
Ajp notes-chapter-04
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 

Recently uploaded

Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
pvpriya2
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
nedcocy
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
Indrajeet sahu
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
PriyankaKilaniya
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
DharmaBanothu
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
Kamal Acharya
 
Presentation on Food Delivery Systems
Presentation on Food Delivery SystemsPresentation on Food Delivery Systems
Presentation on Food Delivery Systems
Abdullah Al Noman
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Balvir Singh
 
AI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdfAI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdf
mahaffeycheryld
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
Kamal Acharya
 
This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...
DharmaBanothu
 
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdfAsymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
felixwold
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
Introduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.pptIntroduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.ppt
Dwarkadas J Sanghvi College of Engineering
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
PreethaV16
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
wafawafa52
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
Assistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdfAssistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdf
Seetal Daas
 

Recently uploaded (20)

Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
 
Presentation on Food Delivery Systems
Presentation on Food Delivery SystemsPresentation on Food Delivery Systems
Presentation on Food Delivery Systems
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
 
AI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdfAI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdf
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
 
This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...
 
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdfAsymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
 
Introduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.pptIntroduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.ppt
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
Assistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdfAssistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdf
 

Background

  • 1. ❮ Previous Next ❯ CSS Backgrounds The CSS background properties are used to define the background effects for elements. CSS background properties: • background-color • background-image • background-repeat • background-attachment • background-position Background Color The background-color property specifies the background color of an element. The background color of a page is set like this: Example body { background-color: lightblue; } Try it Yourself » With CSS, a color is most often specified by:
  • 2. • a valid color name - like "red" • a HEX value - like "#ff0000" • an RGB value - like "rgb(255,0,0)" Look at CSS Color Values for a complete list of possible color values. In the example below, the <h1>, <p>, and <div> elements have different background colors: Example h1 { background-color: green; } div { background-color: lightblue; } p { background-color: yellow; } Try it Yourself » Background Image The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element. The background image for a page can be set like this:
  • 3. Example body { background-image: url("paper.gif"); } Try it Yourself » Below is an example of a bad combination of text and background image. The text is hardly readable: Example body { background-image: url("bgdesert.jpg"); } Try it Yourself » Note: When using a background image, use an image that does not disturb the text. Background Image - Repeat Horizontally or Vertically By default, the background-image property repeats an image both horizontally and vertically. Some images should be repeated only horizontally or vertically, or they will look strange, like this:
  • 4. Example body { background-image: url("gradient_bg.png"); } Try it Yourself » If the image above is repeated only horizontally ( background-repeat: repeat-x; ), the background will look better: Example body { background-image: url("gradient_bg.png"); background-repeat: repeat-x; } Try it Yourself » Tip: To repeat an image vertically, set background-repeat: repeat-y; Background Image - Set position and no-repeat Showing the background image only once is also specified by the background- repeat property:
  • 5. Example body { background-image: url("img_tree.png"); background-repeat: no-repeat; } Try it Yourself » In the example above, the background image is shown in the same place as the text. We want to change the position of the image, so that it does not disturb the text too much. The position of the image is specified by the background-position property: Example body { background-image: url("img_tree.png"); background-repeat: no-repeat; background-position: right top; } Try it Yourself » Background Image - Fixed position To specify that the background image should be fixed (will not scroll with the rest of the page), use the background-attachment property:
  • 6. Example body { background-image: url("img_tree.png"); background-repeat: no-repeat; background-position: right top; background-attachment: fixed; } Try it Yourself » Background - Shorthand property To shorten the code, it is also possible to specify all the background properties in one single property. This is called a shorthand property. The shorthand property for background is background : Example body { background: #ffffff url("img_tree.png") no-repeat right top; } Try it Yourself » When using the shorthand property the order of the property values is: • background-color • background-image • background-repeat • background-attachment • background-position
  • 7. Exercise 1 » Exercise 2 » Exercise 3 » Exercise 4 » Exercise 5 » ❮ Previous Next ❯ It does not matter if one of the property values is missing, as long as the other ones are in this order. Test Yourself with Exercises! All CSS Background Properties Property Description background Sets all the background properties in one declaration background- attachment Sets whether a background image is fixed or scrolls with the rest of the page background-clip Specifies the painting area of the background background-color Sets the background color of an element background-image Sets the background image for an element background-origin Specifies where the background image(s) is/are positioned background-position Sets the starting position of a background image background-repeat Sets how a background image will be repeated background-size Specifies the size of the background image(s)
  • 8. Copyright 1999-2019 by Refsnes Data. All Rights Reserved.