css-grid

CSS-only masonry layout

|▌冷眼眸甩不掉的悲伤 提交于 2020-08-20 11:36:11
问题 I need to implement a fairly run-off-the-mill masonry layout. However, for a number of reasons I don't want to use JavaScript to do it. Parameters: All elements have the same width Elements have a height that cannot be calculated server side (an image plus various amounts of text) I can live with a fixed number of columns if I have to there is a trivial solution to this that works in modern browsers, the column-count property. The problem with that solution is that elements are ordered in

CSS Grid two columns in the first row and three columns in the second and third row [duplicate]

拟墨画扇 提交于 2020-08-20 10:32:25
问题 This question already has answers here : Can I have a varying number of columns per row in a CSS grid? (5 answers) Closed 4 months ago . I am trying to understand how to achieve a layout that takes two columns in the first row and three columns in the second row, third row, and so on. <section> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> <div>6</div> <div>7</div> <div>8</div> </section> //CSS section { display: grid; grid-template-columns: 1fr 1fr; } The above code will