Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
103
rated 0 times [  108] [ 5]  / answers: 1 / hits: 15682  / 13 Years ago, fri, march 9, 2012, 12:00:00

I have this JS code that I use to create a new div (I create several, dynamically). I want my text to be in the centered vertically and aligned to the left side of the div. Any suggestions on what to do? Here is my code:



        var leftDiv = document.createElement(div); //Create left div
leftDiv.id = left; //Assign div id
leftDiv.setAttribute(style, float:left;width:70%;vertical-align:middle; height:26px;); //Set div attributes
leftDiv.style.background = #FFFFFF;
leftDiv.style.height = 70;
user_name = document.createTextNode(fullName + ' '); //Set user name


One other thing. This code will center the text horizontally and it seems to gravitate to the top of the div instead of the middle.


More From » html

 Answers
10

If the height of div is constant (seems like it is 70px) than you can use line-height: 70px; to render any text vertically centered.


[#86960] Thursday, March 8, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
allanw

Total Points: 421
Total Questions: 132
Total Answers: 102

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
;