I have three small divs that appear inside the same parent div. The second (middle) div is variable in size, as it displays text of slightly different lengths (month names).
How do I make the center of a div align with the center of the parent div so that the first and third divs align correctly in the remaining space?
CSS still exists (but it doesn't work yet):
div.calendartitle { //The parent
display: block;
width: 117px;
height: 15px;
border-style: solid;
border-color: black;
font-size: small;
border-width: 1px;
text-align: center;
}
div.calendartitleelement { //The three sub-divs.
display: block;
float: left;
margin-left: auto;
margin-right: auto;
width: 38px;
}
HTML is generated in JS:
var html = "<div class='calendartitle'>";
html += "<div class='calendartitleelement calendertitleclickable' onclick='buildCalendar(" + previousWeekStartingDay + "," + previousMonth + ");'><<</div>";
html += "<div class='calendartitleelement'>" + months[month] + "</div>";
html += "<div class='calendartitleelement calendertitleclickable' onclick='buildCalendar(" + nextWeekStartingDay + "," + nextMonth + ");'>>></div></div>";
$("#calendardisplay").prepend(html);
source
share