简体   繁体   English

如何计算居中的div的左侧空间

[英]How calculate centered div's left side space

I have centered div for my side. 我将div放在我的中心。 Now I want to calculate left side blank space. 现在我要计算左侧的空白空间。 How to do it by jquery. 如何通过jQuery做到这一点。

My Markup 我的标记

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

My Css 我的CSS

#page_main
{
    width:100%;
}
.content
{
    width:960px;
    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 . 您可以使用offset()返回元素相对于document的坐标。 It return Object with top and left properties. 它返回带有topleft属性的Object。 DEMO DEMO

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何计算居中div的顶部和左侧位置? - How to calculate top and left positions of a centered div? 如何将文字与居中文字的左侧对齐? - How to align text to the left side of centered text? 我如何计算text-align:居中div中左边框和文本开头之间的空格? - How I can count the space between left border and begin of a text in the text-align: centered div? 如何使用jqueryui仅在左侧调整div的大小,并且仅在左侧调整相邻的div的大小? - How can I resize a left side div on its right side only, and it's neighboring right side div, on its left side only, using jqueryui? 将 2 张图像并排放置,没有空间并居中 - putting 2 images side by side with no space and centered 如何检查单击的div(左侧或右侧)的至少一侧是否没有其他div - How to check if at least one side of a clicked div (left or right) is free of other div's 如何显示NavigationMenu div滑块的左侧 - how to display navigationMenu div left side of the slider 如何在div的右侧创建对象(div:left) - How to create an object to the right side of the div (div:left) 如何从居中的div中的可移动div获得安全的左位置规​​格? - How I get the safe specification of left position from a movable div in a centered div? 计算相对内部的居中绝对div - calculate centered absolute div inside relative
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM