Is there a way to center a box vertically within another box using jQuery instead of CSS? I believe it's more reliable.
var textH = $(".Text").height();
var vertAlign = ((140 - textH)/2);
$(".Text").css({
marginTop: 'vertAlign'
});
I'm struggling with the details. The goal is for the output to be half of the available vertical space in pixels.
UPDATE
Originally, the text block was a span inside a div. The div had a fixed height (e.g., 140 px), while the span's height varied based on the text content. However, I needed the text block to be editable, so I switched it to a text area. Unfortunately, managing the dimensions of the text area turned out to be challenging since I had to set static height and width values. As a result, the height of the text block became non-variable, causing issues in determining the margin-top spacing from its parent. What would be the best course of action in this situation?