How to center a div horizontally and vertically in CSS?

clock icon

asked 9 months ago Asked

message

4 Answers

eye

122 Views

 I'm struggling to perfectly center a div both horizontally and vertically using CSS. I've tried various methods, including using flexbox and positioning, but can't seem to get it right. Any insights or best practices?

4 Answers

One way to achieve this is by using the following CSS code:

 

.container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

One way to achieve this is by using the following CSS code:

.center-div {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

Prueba de postjfidsaifjisauhfdiuhsaiufhisahfidsafhduisahifsauPrueba de postjfidsaifjisauhfdiuhsaiufhisahfidsafhduisahifsauPrueba de postjfidsaifjisauhfdiuhsaiufhisahfidsafhduisahifsauPrueba de postjfidsaifjisauhfdiuhsaiufhisahfidsafhduisahifsauPrueba de postjfidsaifjisauhfdiuhsaiufhisahfidsafhduisahifsauPrueba de postjfidsaifjisauhfdiuhsaiufhisahfidsafhduisahifsauPrueba de postjfidsaifjisauhfdiuhsaiufhisahfidsafhduisahifsauPrueba de postjfidsaifjisauhfdiuhsaiufhisahfidsafhduisahifsau

Write your answer here

Top Questions