In the given code background-clip: padding-box; is working but the background-clip: content-box; isn't working. Please tell me what is wrong here. I found that padding must be there for the background-clip property to work and I have added the padding as well.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
.temp {
width: 400px;
height: 300px;
background-color: rgb(255, 153, 141);
background-clip: content-box;
border: 9px dotted blue;
margin: 20px;
float: left;
text-align: center;
/* background-clip: padding-box; */
}
.temp h3 {
padding-top: 90px;
}
</style>
<body>
<div class="temp">
<h3>Hasnain</h3>
</div>
<div class="temp">
<h3>Zain</h3>
</div>
<div class="temp">
<h3>brothers</h3>
</div>
</body>
</html>
CodePudding user response:
Your code is working, you just added the padding to the wrong element ".temp h3" instead of ".temp"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
.temp {
width: 400px;
height: 300px;
background-color: rgb(255, 153, 141);
background-clip: content-box;
border: 9px dotted blue;
margin: 20px;
float: left;
text-align: center;
/* background-clip: padding-box; */
}
.temp {
padding-top: 90px;
}
</style>
<body>
<div class="temp">
<h3>Hasnain</h3>
</div>
<div class="temp">
<h3>Zain</h3>
</div>
<div class="temp">
<h3>brothers</h3>
</div>
</body>
</html>