Why doesn't displaying the grid using a grid template area work?
P粉541796322
P粉541796322 2023-09-09 16:28:13
0
1
557

I'm trying to achieve element arrangement via grid template area but it doesn't work. I'm trying to use a grid system to arrange blocks vertically and horizontally. Use the picture on the left and the text on the other side. Why doesn't this code work?

.news__wrapper { display: grid; grid-template-areas: "a a c" "b b c"; } .news__item { display: flex; align-items: center; justify-content: center; } .news__item-image { width: 349px; height: 360px; } .news__item-image { background: "url(https://place-hold.it/300x500) 50% 50% no-repeat"; }

Lorem,

Lorem ipsum

Lorem,

Lorem

Lorem,

Lorem ips

https://codesandbox.io/s/blissful-bush-tngxm8?file=/src/styles.css

P粉541796322
P粉541796322

reply all (1)
P粉513318114

When you usegrid-template-areas, you need to assigngrid-areavalues to elements within the grid.
In short, adding the followingcsscode will achieve the desired result:

.news__item:first-child { grid-area: a; } .news__item:nth-child(2) { grid-area: b; } .news__item:nth-child(3) { grid-area: c; }
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!