CSS Properties: How to set different background properties in one declaration?
Solution:
HTML Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" /><!-- Set the character encoding of the HTML document -->
<title>How to set different background properties in one declaration</title><!-- Set the title of the HTML document -->
<style> /* CSS style start*/
body { /* Apply styles to the body element */
margin-top: 300px; /* Set the top margin of the body to 300px */
background: #6699FF no-repeat center/80% url("https://www.w3resource.com/images/w3resourcelogo.gif"); /*Set multiple background properties in one declaration */
}
</style>
</head>
<body>
<p>w3resource Tutorial</p><!-- Display the text "w3resource Tutorial" in a paragraph -->
</body>
</html>
Explanation:
- This HTML document sets a background image for the body element using CSS.
- The background property is used to specify multiple background properties in a single declaration.
- #6699FF sets the background color to a shade of blue.
- no-repeat ensures that the background image is not repeated.
- center/80% positions the background image at the center horizontally and vertically, covering 80% of the background area.
- url("https://www.w3resource.com/images/w3resourcelogo.gif") specifies the URL of the background image, in this case, the W3Resource logo.
Live Demo:
See the Pen background-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
Yes | Yes | Yes | Yes | No |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics