section { display: flex; flex-wrap: wrap; gap: 10px; } div { background-color: aquamarine; } @media (min-width: 400px) { div { background-color: gold; width: calc((100% - 10px) / 2); } } @media (min-width: 500px) { div { background-color: orange; width: calc((100% - 30px) / 4); } }
body { font-family: sans-serif; padding: 20px; } div { padding: 10px; } p:not(:first-child) { margin-top: 10px; }
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="../assets/reset.css" rel="stylesheet"> <link href="setup.css" rel="stylesheet"> <link href="style.css" rel="stylesheet"> </head> <body> <section> <div> <p>This element is responsive. I’ll add some text here so we have something to look at and so that it wraps, but the text itself isn’t important, at the moment.</p> </div> <div> <p>This is another responsive element, with some more text in it. Again the text doesn’t really matter, I just want a bit of stuff in here. A few lines, is all.</p> </div> <div> <p>And a third one, to have an element for each rule. I probably should just grab some lorem ipsum, but at this point I’m committed to typing nonsense.</p> </div> <div> <p>Let’s have a fourth one here, to better help show a multi-column layout as we get wider. Writing dummy text manually is oddly calming?</p> </div> </section> </body> </html>