Calculating the actual content width or height

D

dhtml

David said:
Interesting. Whey not just save the inline padding style?

Shorthand values don't always return the value you gave it.

<div style="padding: 10px 0">
</div>

var s = div.style.padding;

Variable - s - might be empty string in some browsers. It is in Safari
2. So, if it were saved and then put back, you'd end up removing padding.

A similar problem occurs with getComputedStyle(el,'').padding. Most
browsers return empty string instead of a shorthand value.

Feature test with a side effect.

Garrett
 
T

Thomas 'PointedEars' Lahn

dhtml said:
Shorthand values don't always return the value you gave it.

That's no good reason at all to resort to inefficient text parsing.
<div style="padding: 10px 0">
</div>

var s = div.style.padding;

Variable - s - might be empty string in some browsers. It is in Safari
2. So, if it were saved and then put back, you'd end up removing padding.

A similar problem occurs with getComputedStyle(el,'').padding. Most
browsers return empty string instead of a shorthand value.

"Most" is wishful (or paranoid) thinking. In any case, you have
paddingLeft, paddingTop, paddingRight, and paddingBottom.
Feature test with a side effect.

A good feature test would handle that.


PointedEars
 
D

David Mark

Shorthand values don't always return the value you gave it.

<div style="padding: 10px 0">
</div>

var s = div.style.padding;

Variable - s - might be empty string in some browsers. It is in Safari
2. So, if it were saved and then put back, you'd end up removing padding.

That's an interesting quirk. Normally I avoid shorthand for things
like this.
A similar problem occurs with getComputedStyle(el,'').padding. Most
browsers return empty string instead of a shorthand value.

I would expect all of them to! Certainly I wouldn't use shorthand
with getComputedStyle.

[snip]
 
D

dhtml

David said:
That's an interesting quirk. Normally I avoid shorthand for things
like this.

And if you had:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>height test </title>
</head>
<body style="padding-top: 1px">
</body>
</html>

then:
document.body.style.padding == ""

- is true in FF 3, OP 9.5, Safari.

setting cssText seems to work pretty well. Thomas seems to think that
the browser having to parse the string would be inefficient. I'm not
sure if he tested this or not.

I would hope the browser would have optimized the css parsing. I do not
know if storing and setting individual t/l/b/r property values would be
faster. It's a little more cumbersome than getting and setting cssText.

Garrett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top