获取div元素的宽度 [英] getting width of a div element

查看:82
本文介绍了获取div元素的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML:

<a id="postanad"  href="postad.php">Make a Post</a>

CSS:

#header #postanad {
    position: absolute;
    top: 50px;
    left: 250px ;
    background: #000 url(postad.gif) repeat-x 0% 100%;    
    font: bold 19px Tahoma, 'trebuchet MS', Sans-serif; 
    padding: 5px;


}

如何确定 div 元素采用的像素/em 大小,以便我可以使背景图像 postad.gif 具有相同的宽度?

How do I determine the size in pixels/ems that the div element is taking so that I can make the background image postad.gif to be of the same width?

明确地说,我不想动态确定宽度,但只想知道它占用了多少空间,以便我可以在 PS 中绘制背景图像.

Just to be clear I don't want to determine the width dynamically , but just want to know how much space it is taking so that I can draw a background image in PS.

推荐答案

如果您对 jQuery 感到满意,则可以使用 $("#postanad").width().

If you're comfortable with jQuery, you can just use $("#postanad").width().

这篇关于获取div元素的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆