📜  justify center wont wotk with max-width css Code Example(1)

📅  最后修改于: 2023-12-03 15:17:07.131000             🧑  作者: Mango

justify center not working with max-width CSS

When using a max-width property on an element and trying to center its contents using the justify-content: center property, you may encounter an issue where the contents are not centered as expected.

This is because justify-content only works on flexbox containers, and when max-width is applied, it changes the display property of the element to block.

Here's an example of the CSS code causing this issue:

.container {
  max-width: 600px;
  justify-content: center;
}

To overcome this issue, you can either:

  1. Add the display: flex property to the container:
.container {
  display: flex;
  max-width: 600px;
  justify-content: center;
}
  1. Align the contents using the text-align: center property:
.container {
  max-width: 600px;
  text-align: center;
}

Markdown:

justify center not working with max-width CSS

When using a max-width property on an element and trying to center its contents using the justify-content: center property, you may encounter an issue where the contents are not centered as expected.

This is because justify-content only works on flexbox containers, and when max-width is applied, it changes the display property of the element to block.

Here's an example of the CSS code causing this issue:

.container {
  max-width: 600px;
  justify-content: center;
}

To overcome this issue, you can either:

  1. Add the display: flex property to the container:
.container {
  display: flex;
  max-width: 600px;
  justify-content: center;
}
  1. Align the contents using the text-align: center property:
.container {
  max-width: 600px;
  text-align: center;
}