A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/html-css-exercise/css-properties/background-image-origin-answer.php below:

Website Navigation


CSS Properties: How to set the background image start from the upper left corner of the content?

CSS Properties: How to set the background image start from the upper left corner of the content?Last update on February 16 2024 13:18:52 (UTC/GMT +8 hours)

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html>
<html>
<head>
<title>How to set the background image start from the upper left corner of the content</title>
<style type="text/css">/* CSS style start*/
#xyz1 {
border: 8px solid blue; /* Set border properties for div with id "xyz1" */
padding: 40px; /* Set padding properties for div with id "xyz1" */
background: url(https://www.w3resource.com/images/w3resource-logo.png); /* Set background image for div with id "xyz1" */
background-repeat: no-repeat; /* Set background image to not repeat */
}
#xyz2 {
border: 8px solid blue; /* Set border properties for div with id "xyz2" */
padding: 40px; /* Set padding properties for div with id "xyz2" */
background: url(https://www.w3resource.com/images/w3resource-logo.png); /* Set background image for div with id "xyz2" */
background-repeat: no-repeat; /* Set background image to not repeat */
background-origin: border-box; /* Set the origin of the background image to the border box */
}
#xyz3 {
border: 8px solid blue; /* Set border properties for div with id "xyz3" */
padding: 40px; /* Set padding properties for div with id "xyz3" */
background: url(https://www.w3resource.com/images/w3resource-logo.png); /* Set background image for div with id "xyz3" */
background-repeat: no-repeat; /* Set background image to not repeat */
background-origin: content-box; /* Set the origin of the background image to the content box */
}
</style>
</head>
<body>
<p>No background-origin (padding-box is default):</p><!-- Display text -->
<div id="xyz1"><!-- Display a div with id "xyz1" -->
<h2>Background image origin</h2><!-- Display a heading -->
<p>The background-origin CSS property determines the background positioning area, that is the position of the origin of an image specified using the background-image CSS property.</p><!-- Display a paragraph -->
</div>
<p>background-origin: border-box:</p><!-- Display text -->
<div id="xyz2"><!-- Display a div with id "xyz2" -->
<h2>Background image origin</h2><!-- Display a heading -->
<p>The background-origin CSS property determines the background positioning area, that is the position of the origin of an image specified using the background-image CSS property.</p><!-- Display a paragraph -->
</div>
<p>background-origin: content-box:</p><!-- Display text -->
<div id="xyz3"><!-- Display a div with id "xyz3" -->
<h2>Background image origin</h2><!-- Display a heading -->
<p>The background-origin CSS property determines the background positioning area, that is the position of the origin of an image specified using the background-image CSS property.</p><!-- Display a paragraph -->
</div>
</body>
</html>

Explanation:

Live Demo:

See the Pen background-image-origin-answer by w3resource (@w3resource) on CodePen.

See the solution in the browser

Supported browser

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4