- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Style backgroundOrigin Property
The background-origin property is used to set or get the background origin i.e. its relative position. It can be relative to any of the four box model areas.
Syntax
Following is the syntax for −
Setting the backgroundOrigin property −
object.style.backgroundOrigin = "padding-box|border-box|content-box|initial|inherit"
Values
The above property values are explained as follows −
Sr.No | Value & Description |
---|---|
1 | padding-box For having the background image positioned relative to the padding box. It is the default value. Default value. The background image is positioned relative to the padding box. |
2 | border-box For having the background image positioned relative to border box. |
3 | content-box To have background image positioned relative to content box. |
4 | initial For setting this property to initial value. |
5 | inherit To inherit the parent property value. |
Example
Let us look at an example for the backgroundOrigin property −
<!DOCTYPE html> <html> <head> <style> #DIV1 { margin: 20px; box-shadow: 0 0 5px black; padding: 30px; background: url("https://www.tutorialspoint.com/power_bi/images/power-bi-minilogo.jpg"); background-origin: content-box; background-repeat: no-repeat; background-size: cover; font-size: 24px; } div>p { box-shadow: 0 0 5px darkgrey; } </style> <script> function changeBackOrigin(){ document.getElementById("DIV1").style.backgroundOrigin="padding-box"; document.getElementById("Sample").innerHTML="The background origin is now set to to padding-box"; } </script> </head> <body> <h2>PowerBI Tutorial</h2> <div id="DIV1"> <p>Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI... Learn PowerBI...Learn PowerBI...</p> </div> <p>Change the above div background origin by clicking the below button</p> <button onclick="changeBackOrigin()">CHANGE ORIGIN</button> <p id="Sample"></p> </body> </html>
Output
This will produce the following output −
On clicking the CHANGE ORIGIN button −
Advertisements