3
I’m starting my studies with CSS Grid and to train I’m trying to make a simple menu, the structure of my grid has 4 columns for 4 lines, as defined in the code.
I am trying to make the menu using a list but I have no idea how to position these elements on my grid, as I will position them in a linear way and I have 4 columns and 4 rows ?
I must place each element in a column ?
I can position all elements even the site having 4 columns ?
Below follows my code of what I tried to do, but it did not work, if you can give me a direction I thank you and much !!!
index.html
<body>
<div class="container">
<div class="item1">
<ul class="texto">
<li>Inicio</li>
<li>Sobre</li>
<li>Github</li>
<li>Linkedin</li>
</ul>
</div>
<div class="item2">Header</div>
<div class="item3">Conteudo</div>
<div class="item4">Footer</div>
</div>
</body>
main css.
* {margin: 0px;}
.item1 {grid-area: menu;}
.item2 { grid-area: cabecalho;}
.item3 {grid-area: conteudo;}
.item4 {grid-area: rodape;}
.container {
display: grid;
grid-template-rows: 100px 200px 400px 200px;
grid-template-areas: 'menu menu menu menu'
'cabecalho cabecalho cabecalho cabecalho'
'conteudo conteudo conteudo conteudo'
'rodape rodape rodape rodape';
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
}
.container > div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 20px 0;
font-size: 30px;
}
css content.
ul {
box-sizing: border-box;
display: inline;
text-decoration: none;
}
Thanks for the help, I asked if it was possible to put word face in a different column because I thought that was the right way to do it but as I saw n seems very productive kkk, one more question I could use flex-box to "set" the elements in each column or it would not be "correct" to do ? pq n have market experience so would like to do something similar to reality, Thank you !
– Pedro
@Giovannimanganotti yes this is a great opportunity to join Grid + Flex, see the EDIT which I did at the end of the reply including this option to use Flex to distribute the Menu items
– hugocsl
humm just saw, understood how it works, now it’s a little clearer this idea of using flex-box along with css grid, Thanks for the help !!!
– Pedro
@Giovannimanganotti if you are interested I made a new edition in the answer, I corrected a config of Felx in the LI to be more aligned with the Grid of the Father’s olunas, and also I made a new code this time using a Sub-Grid, putting Display:Grid in the UL also to align the LI right
– hugocsl