How to set relative 50% 50% position using JS?
I tried:
document.getElementById("id").style.position = "relative 50% 50%";
but it don’t seems to work…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have to set them individually.
I made a variable to point to the
styleobject, because we are modifying more than one property and becausewith() { ... }is considered harmful.Also, I set the
50%to both properties because of right to left assignment, and because assignment of this string to the two properties isn’t a problem (make sure you understand how this works, e.g.var a = b = []will setaandbto the sameArrayobject, often not desired).jsFiddle.