css vertical align middle code example
Example 1: css vertical center
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.parent {
display: flex;
flex-direction: column;
justify-content: center;
}
Example 2: css vertical align middle
.center {
display: flex;
justify-content: center;
align-items: center;
}
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
Example 3: css vertical center
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.parent {
display: flex;
flex-direction: column;
justify-content: center;
}
Example 4: how to center a div vertically and horizontally
.container{
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width:
height:
}
Example 5: text vertical align css
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style type="text/css">
div {
display: table-cell;
width: 250px;
height: 200px;
vertical-align: middle;
}
</style>
</head>
<body>
<div>Vertically aligned text</div>
</body>
</html>
Example 6: 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>