After conducting some research, it appears that there are four options available to you:
Option 1: Using display table-cell for the parent div
If you are comfortable utilizing display:table-cell
on your parent div, here is one way to achieve the desired effect:
.area{
height: 100px;
width: 100px;
background: red;
margin:10px;
text-align: center;
display:table-cell;
vertical-align:middle;
}
View Live Demo
Option 2: Parent div with display block and child div as table-cell
.area{
height: 100px;
width: 100px;
background: red;
margin:10px;
text-align: center;
display:block;
}
.content {
height: 100px;
width: 100px;
display:table-cell;
vertical-align:middle;
}
View Live Demo
Option 3: Floating parent div with content div as table-cell
.area{
background: red;
margin:10px;
text-align: center;
display:block;
float: left;
}
.content {
display:table-cell;
vertical-align:middle;
height: 100px;
width: 100px;
}
View Live Demo
Option 4: Relative positioning for parent div and absolute positioning for content
This option may require custom styling for each specific implementation. The content div needs a set height to accommodate the text, and the margin-top is calculated based on this height. You can adjust the height percentage of the content div and multiply it by -0.5 to determine the margin-top value for different scenarios manually.
.area{
position:relative;
display:block;
height:100px;
width:100px;
border:1px solid black;
background:red;
margin:10px;
}
.content {
position:absolute;
top:50%;
height:50%;
width:100px;
margin-top:-25%;
text-align:center;
}
View Live Demo