w3resource

CSS Properties: How to set different background properties in one declaration?

Go to Exercise page

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

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
Yes Yes Yes Yes No

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/html-css-exercise/css-properties/background-answer.php