📜  在 html 中将 p、div、容器居中对齐 - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:06.638000             🧑  作者: Mango

代码示例1
//align p
p {
  text-align: center;
}


//align container
/* Method 1: */
.container {
  display: flex;
  justify-content: center; // (or use)    margin: 0 auto;
  align-items: center;
}

/* Method 2: */
.container {
    display: grid;
    place-items: center
}

/* Method 3: */
.center-div {
    margin: auto;
}

/* Method 4: */
.center-div {
  position: absolute;
  left: 50%;
  top: 50%;
}