Currently, I am in the process of designing a webpage called vijesti.html using CSS Grid layout to showcase three different types of news items:
click here for grid layout under 800px
click here for grid layout over 800px
The "Main News" section (.mainNews) occupies the entire width. It is set to have a 1:2 aspect ratio on screens wider than 800px and 1:1 on smaller screens.
The "Vertical News" section (.verticalNews) takes up 25% width on larger screens and 50% on smaller screens. Its height is always double its width.
The "Square News" section (.squareNews) has equal width and height. It covers 25% width on bigger screens and 50% on smaller screens.
I attempted to use grid-template-areas but encountered an error stating "Invalid property value." How can I correctly configure grid-template-areas for this design, or is there an alternative solution?
This is the code snippet I composed:
<body>
<div class="news">
<div class="mainNews">News</div>
<div class="verticalNews">News</div>
<div class="squareNews">News</div>
<div class="squareNews">News</div>
<div class="squareNews">News</div>
<div class="squareNews">News</div>
<div class="verticalNews">News</div>
<div class="squareNews">News</div>
<div class="squareNews">News</div>
<div class="squareNews">News</div>
<div class="squareNews">News</div>
<div class="verticalNews">News</div>
<div class="verticalNews">News</div>
</div>
</body>
body {
background-color: #cdc3a9;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.news {
margin: 0;
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-gap: 10px;
grid-template-areas:
"main main main main"
"vertical square square vertical"
"vertical square square vertical"
"square square vertical vertical"
"square square vertical vertical"
}
.mainNews {
grid-area: main;
background-color: #c9daf8;
}
.verticalNews {
grid-area: vertical;
background-color: #fff2cc;
}
.squareNews {
grid-area:square;
background-color: #f4cccc;
}
Adding media queries is part of my future plans, but my primary focus right now is resolving this issue.