Javascript DOM CSS Style backgroundClip Property

Introduction

Specify the painting area of the background:

document.getElementById("myDIV").style.backgroundClip = "content-box";

Click the button to set the background-clip property of the DIV element to "content-box":

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {//from w w w .  jav a2s .  co m
  width: 300px;
  height: 300px;
  padding: 50px;
  background-color: coral;
  background-clip: border-box;
  color: white;
  border: 5px dotted lightgrey;
}
</style>
</head>
<body>
<button onclick="myFunction()">Test</button>

<div id="myDIV">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</div>

<script>
function myFunction() {
  document.getElementById("myDIV").style.backgroundClip = "content-box";
}
</script>

</body>
</html>

The backgroundClip property sets or gets the painting area of the background.

Property Values

Value Description
border-box Default. The background is clipped to the border box
padding-box The background is clipped to the padding box
content-box The background is clipped to the content box
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

The backgroundClip property returns a String representing the background-clip property of an element.




PreviousNext

Related