Answers for "CSS cetner text"

3

css center text in div

/* For horizontal align: */
parent-element {text-align:center;}
/* For horizontal and vertical align: */
parent-element {position: relative;}
element-to-be-centered {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

/* See https://www.w3schools.com/css/css_align.asp for more info */
Posted by: Guest on October-25-2020
2

css how to center text

/* Using flex to center anything*/
.parent{
  display: flex;
  justify-content: center; /* Centering Horizantly */
  align-items: center; /* Centering Vertically */
  /* Every element inside this div will be centered*/
}
/* Using Line Height*/
.main-div{
  width: 50%;
  height: 40px;
}
.main-div p{
  line-height: 40px; /* Same as parent height*/
  /* p will be centered vertically inside its parent div*/
}
/* CSS Property */
p{
  text-align: center;
}
Posted by: Guest on June-12-2021

Browse Popular Code Answers by Language