Alignment does not work in a div

Asked

Viewed 31 times

0

I’m trying to line up a div in the center, but it’s on the left. I’ve tried using <div align="center">, tried to use text-align and align-items in css, but nothing works.

#json {
      background-color:rgb(59, 54, 54);
      color:rgb(204, 198, 198);
      border-radius: 8px;
      width: 300px;
      align-items: center;
      text-align:center;
   }
<div id="json"> Conteúdo aqui </div>

  • 1

    adds a margin: 0 auto;

  • worked, thanks!

1 answer

-1


Horizontal centering

To center something horizontally in modern browsers, you can use display: flex; Justify-content: center;

However, in older browsers, such as IE8-9 that does not support flexbox layout, these are not available. To center an element within your parent, use margin: 0 auto;

Source: Margin - Developer.mozilla.org

#json {
      background-color:rgb(59, 54, 54);
      color:rgb(204, 198, 198);
      border-radius: 8px;
      width: 300px;
      text-align:center;
      margin: 0 auto;
   }
<div id="json"> Conteúdo aqui </div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.