I found myself puzzled by the background-image :
background-image in
div
elementWhen the background-image is applied to a
div
, the image appears inside thediv
.background-image in
body
elementWhen the background-image is set on the body, the image shows outside of the body element.
Could someone shed some light on this?
This is what I got as a result https://i.sstatic.net/2rPHn.png
My code:
body{
height: 300px;
width: 300px;
position: absolute;
top: 20%;
left: 20%;
border: 2px solid black;
background-image: url('./alert.png');
background-repeat: no-repeat;
}
div{
border:2px solid red;
width:100px;
height:100px;
border: 2px solid red;
background-image: url('./alert.png');
background-repeat: no-repeat;
position: absolute;
top: 10%;
left: 10%
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<body>
<div>
</div>
</body>
</html>