I am just learning CSS, so as per the cascading system id should have preference over class. the class "box" has a blue background when I applied purple background to the id "outer-box" it should replace the box background, but it appearing as a purple border.
.box {
background-color: blue;
padding: 10px;
}
#outer-box {
background-color: purple;
}
.inner-box {
background-color: red;
}
p {
color: yellow;
margin: 0;
padding: 0;
}
.white-text {
color: white;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS Cascade</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="box" id="outer-box">
<div class="box">
<p>Yellow Text</p>
<div class="box inner-box">
<p class="white-text">White Text</p>
</div>
</div>
<div class="box">
<p>Yellow Text</p>
<div class="box inner-box">
<p class="white-text">White Text</p>
</div>
</div>
</div>
</body>
</html>
2
Answers
It’s not the border that you are seeing. It’s actually the background applied to the outer box, which contains other divs that have other blue blackground, so you get to see only a little of the outer div.
Try adding some divs just under the outer-box with no styling and you can see that the background is applied.
Something like this
#outer-box
is correctly being applied. You just have another box inside that just has a classbox
.You see a "border" of purple and blue because you set
padding: 10px
inbox
class. You’re seeing that padding, not a border.