Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save junaidtk/9416e1235180fb0519db79c8b7f2154a to your computer and use it in GitHub Desktop.
Save junaidtk/9416e1235180fb0519db79c8b7f2154a to your computer and use it in GitHub Desktop.
CSS Verticlally Middle.
1)Using transform styling:
=====================
.child {
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
2) Using the table styling:
==========================
.parent{
display: table;
}
.child{
display: table-cell;
vertical-align: middle;
padding-left: 20px;
}
3)Using the display flex:
=========================
display:flex;
align-items:center;
4) Using the position absolute:
===============================
.parent {
height: 100px;
width: 100px;
position: relative;
}
.child {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
5)Using line-height:
===================
.child{
line-height: 50px;
vertical-align: middle;
}
6)Using -ve margin:
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
height:50px;
margin-top:-25px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment