Bhavan Kumar Natarajan Bhavan Kumar Natarajan - 1 year ago 42
jQuery Question

How calculate centered div's left side space

I have centered div for my side. Now I want to calculate left side blank space. How to do it by jquery.

My Markup

<main id="page_main" role="main">
<div class="content">

My Css

margin:0px auto;

Now I want to calculate the screen's left side blank space. Can you help me how to do it?


You can use offset() which returns coordinates of element relative to document. It return Object with top and left properties. DEMO

$(window).on("resize", function () {
 var c = $(".content").offset().left;