-1

Here's my code:

body {
  background-color: brown;
  display: block;
}
.domma { /*This part went wrong.*/
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}
.grid {
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  gap: 15px;
  width: 500px;
  height: 500px;
}
.grid div {
  background-color: black;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
}
<body>
    <div class="domma">
      <div class="grid">
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
        <div>6</div>
        <div>7</div>
        <div>8</div>
        <div>9</div>
      </div>
    </div>
</body>

result:

enter image description here

I hope ".domma"(body) can center for vertical.

Then I writtedalign-items: center;.

But this is invalid.

I don't know how to make it correct.

I need help, please HELP ME! Thanks!!!!

KuldipKoradia
  • 3,005
  • 7
  • 20
红日初升
  • 141
  • 1
  • 7

2 Answers2

1

try adding height and width to .domma, something like this:

.domma {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  min-heigh: 100vh;
  min-width: 100vw;
}

Khibar
  • 21
  • 1
  • 5
  • Thank you. But a problem occurred after the modification: (https://i.loli.net/2021/01/28/vYbgEdpTMa9GrPz.png) There are scroll bars on the right and bottom. – 红日初升 Jan 28 '21 at 02:01
  • that is probably some margin of some parent element which is extending beyond the width/height of your screen. – Khibar Jan 28 '21 at 09:07
-1

You just change the .domma css poperty and replace some CSS like:

.domma {
  width: 100%;
  display: grid;
  align-content: space-between;
  justify-content: space-around;
}

Here the full code:

body {
  background-color: brown;
  display: block;
}
.domma {
  width: 100%;
  display: grid;
  align-content: space-between;
  justify-content: space-around;
}
.grid {
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  gap: 15px;
  width: 500px;
  height: 500px;
}
.grid div {
  background-color: black;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
}
<body>
    <div class="domma">
      <div class="grid">
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
        <div>6</div>
        <div>7</div>
        <div>8</div>
        <div>9</div>
      </div>
    </div>
</body>
Md. Abu Sayed
  • 2,396
  • 2
  • 18
  • 26