Answers for "css div align center vertical"

CSS
7

css vertical align middle

/* Flex */
.center {
  	display: flex;
  	justify-content: center;
  	align-items: center;
}
/* Without Flex */
.parent {
  	position: relative;
}
.child {
  	position: absolute;
  	top: 50%;
  	transform: translateY(-50%);
}
Posted by: Guest on April-19-2021
15

css align items vertical center

.parent {
  display: flex;
  justify-content: center;
  align-items: center;
}
Posted by: Guest on October-31-2020
9

css vertical center

/* 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 March-18-2020
26

css vertical center

/*Remove comment to become a better programmer. */
/* 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 January-11-2021
8

css center vertically

<style>
.container {
  height: 200px;
  position: relative;
  border: 3px solid green;
}

.center {
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
</style>

<div class="container">
  <div class="center">
    <p>I am vertically and horizontally centered.</p>
  </div>
</div>
Posted by: Guest on April-01-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