Bhavan Kumar Natarajan Bhavan Kumar Natarajan - 1 year ago 69
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?

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download