There are 38 squares in this code. I’m trying to move the 3 rows on the top to the right 3 squares.
I tried various ways, but it doesn’t work. How do I move these 3 rows on the top to the right 3 squares, so that it is aligned in the center?
If you look at the output, the top 3 rows (8 X 3 = 24 squares) are simply on the left side. I’m trying to align it to the middle. The bottom row which is row4 contains 14 squares in total. I’m trying to align the top 3 rows between square 4 and 11 of row4 (the row at the bottom).
<body>
<div class="container">
<ul>
<div class="div" id="row1">
<li class="square" id="D14"></li>
<li class="square" id="E14"></li>
<li class="square" id="F14"></li>
<li class="square" id="G14"></li>
<li class="square" id="H14"></li>
<li class="square" id="I14"></li>
<li class="square" id="J14"></li>
<li class="square" id="K14"></li>
</div>
<div class="div" id="row2">
<li class="square" id="D13"></li>
<li class="square" id="E13"></li>
<li class="square" id="F13"></li>
<li class="square" id="G13"></li>
<li class="square" id="H13"></li>
<li class="square" id="I13"></li>
<li class="square" id="J13"></li>
<li class="square" id="K13"></li>
</div>
<div class="div" id="row3">
<li class="square" id="D12"></li>
<li class="square" id="E12"></li>
<li class="square" id="F12"></li>
<li class="square" id="G12"></li>
<li class="square" id="H12"></li>
<li class="square" id="I12"></li>
<li class="square" id="J12"></li>
<li class="square" id="K12"></li>
</div>
<div class="div" id="row4">
<li class="square" id="A11"></li>
<li class="square" id="B11"></li>
<li class="square" id="C11"></li>
<li class="square" id="D11"></li>
<li class="square" id="E11"></li>
<li class="square" id="F11"></li>
<li class="square" id="G11"></li>
<li class="square" id="H11"></li>
<li class="square" id="I11"></li>
<li class="square" id="J11"></li>
<li class="square" id="K11"></li>
<li class="square" id="L11"></li>
<li class="square" id="M11"></li>
<li class="square" id="N11"></li>
</div>
</ul>
</div>
</body>
*{
margin: 0;
padding: 0;
}
body {
display: flex;
place-items: center;
justify-content: center;
overflow-x: hidden;
height: 100vh;
background-color: #c0c0c0;
}
.container{
display: grid;
place-items: center;
justify-content: center;
}
.div{
display: flex;
}
ul{
display: grid;
grid-template-columns: 1fr;
}
li{
list-style: none;
display:grid;
place-items: center;
font-size: 0;
}
.square{
margin:.5px;
width: 60px;
height: 60px;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.9);
}
2
Answers
I think I got your problem. Following is the new code you should use along with suggestions.
replace li with div and ul with div so that your code is inline with the conventions of programming
add a justify-content:center in the .div class.
here’s the code:
CSS:
Don’t get rid of the ul element if the blocks really do constitute a list – keep the semantics.
Instead, to correct the HTML syntax, remove those divs within the ul.
Then format the ul as a grid, 14 cells wide, with the 1st, 9th and 17th item in column 4. All the other cells with then go to the desired places.