I am currently working on a code to display 9 boxes in a layout reminiscent of a rubix cube.
#child {
height: 30px;
width: 30px;
float: left;
margin: 1px;
background-color: rgba(235, 26, 224, 0.829);
}
#outer {
position: absolute;
}
<div id="outer">
<div id="inner">
<div id="child"></div>
<div id="child"></div>
<div id="child"></div>
</div>
<div>
<div id="child"></div>
<div id="child"></div>
<div id="child"></div>
</div>
<div>
<div id="child"></div>
<div id="child"></div>
<div id="child"></div>
</div>
</div>
I want to style each of the 9 divs
with different colors using nth-child
, but the browser is treating them as 3 separate elements instead of 9 due to the intermediate div #inner
acting as another parent for #child
.
#child:nth-child(2) {
background-color: blue;
}
#child:nth-child(3) {
background-color: green;
}
#child:nth-child(4) {
background-color: red;
}
#child:nth-child(5) {
background-color: yellow;
}
#child:nth-child(6) {
background-color: black;
}
/* and so forth for all 9 divs */
Is there anyone who can assist me in applying unique styles to the #child
divs using only CSS
?