Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting width of a div element

Tags:

css

width

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;


}

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?

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.

like image 531
gyaani_guy Avatar asked Jan 13 '11 13:01

gyaani_guy


People also ask

How do you find the width of a div element?

To measure the width of a div element we will utilize the offsetWidth property of JavaScript. This property of JavaScript returns an integer representing the layout width of an element and is measured in pixels. Return Value: Returns the corresponding element's layout pixel width.

Can you get the width of an element in CSS?

The width property in CSS specifies the width of the element's content area. This “content” area is the portion inside the padding, border, and margin of an element (the box model). In the example above, elements that have a class name of . wrap will be 80% as wide as their parent element.

How do you find the dimensions of a element?

Use offsetWidth & offsetHeight properties of the DOM element to get its the width and height.

How do you find the width of a container?

For rectangular and square containers, measure length (l) and width (w) of the inside lip of the container, and the diameter (d) of the inside lip for circular containers. Don't worry about the depth or shape of the container beneath the lip; it doesn't matter for this area measurement.


1 Answers

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

like image 198
atfergs Avatar answered Sep 28 '22 11:09

atfergs