Answers for "css center in div block"

CSS
10

css center

/* this will center all children within the parent element. */
.parent {
  display: flex;
  justify-content: center; /* horizontal */
  align-items: center; /* vertical */
}
Posted by: Guest on May-17-2020
2

css center div vertically

/* center vertically */
/* No Flexbox */
.parent {
  position: relative;
}
.child {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}



/* With Flexbox */

.parent {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
Posted by: Guest on December-16-2020

Browse Popular Code Answers by Language