A
A
Alexander2021-07-11 13:56:17
css
Alexander, 2021-07-11 13:56:17

How to responsively place divs (three in a row, and for the mobile version centered one below the other)?

For desktops, the location of blocks that contain 280x300 images should be placed three in a row 60eacd6eaf224180697042.png, and when the screen is reduced, the blocks should be located one below the other, and not be pressed to the left edge, as I do, but placed in the center: 60eacd951f794533293509.png.

Here is my HTML and CSS:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>CSS practice</title>
</head>
<body>
    <div class="wrapper">
        <div class="container">
            <div class="box"><img src="img/photo.jpg" alt="photo"></div>
            <div class="box"><img src="img/photo.jpg" alt="photo"></div>
            <div class="box"><img src="img/photo.jpg" alt="photo"></div>
        </div>
    </div>
</body>
</html>


*{
    margin: 0;
    padding: 0;
}

.wrapper{
    width: 100%;
    position: relative;
}

.container{
    position: inherit;
    width: 100%;
    display: grid;
    grid-template-columns: 280px 280px 280px;
    justify-content: space-around;
}

@media (max-width: 576px)
{
    .container{
        display: block;
        justify-content: center;
        top: 25%;
        left: 25%;
    }
}


I recently started learning HTML and CSS, so tell me what's wrong and how to do it right. I will be grateful

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elena Fire, 2021-07-16
@BormotunJedy

grid is important here?

.container {
  display: flex;
  justify-content: space-around;
  width: 100%;
}
.box {
width: 33%;
}
@media screen and (max-width: 576px) {
  .container {
      flex-wrap: wrap;
      align-items: center;
     }
   .box {
      width: 50%;
     }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question