Reputation: 487
I know my question may sound odd but I was wondering if there was a way to convert CSS percentage into pixels. My goal with this is to calculate widths and heights with percentage values but not have them change when the screen is resized. If there is another way to achieve my goal I would be glad to hear it.
Upvotes: 0
Views: 4695
Reputation: 168
you can do it using javascript. you get the width of the current width of the element and then set that width to the element.
var wid = document.getElementById("mydiv").offsetWidth;
wid+="px"
this returns the width in pixels and you append the "px" to the returned numerical value and then you can set it as below
getElementById("mydiv").setAttribute("style",'width:wid');
you can fix the width of the document at once in the beggining
$(document).ready(function() {
var screenWidth = $(window).width();
$('html,body').css('width', screenWidth + 'px');
});
Upvotes: 2