![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
The <p> is suggested in CSS Spec 2.1 to have a margin of 1.12em, and in Spec 2.0, to have 1.33em... But looks like Firefox and Safari both use 1em for it. And IE use something less... maybe 0.5em I wonder if there is a way to find out how the <p> is defined as a default value in your browser? One way might be to use javascript, but alert(document.getElementById("ha").style.margin_t op) alert(document.getElementById("ha").style.margin) both won't show anything. ("ha" is an ID for a <p> element) |
#3
| |||
| |||
|
|
Seehttp://www.quirksmode.org/dom/getstyles.htmlfor a useful cross-browserish method of getting the current style of an element. |
#4
| |||
| |||
|
|
function getStyle(el,styleProp) { var x = document.getElementById(el); if (x.currentStyle) var y = x.currentStyle[styleProp]; else if (window.getComputedStyle) var y = document.defaultView.getComputedStyle(x,null).getP ropertyValue(styleProp); return y; } alert(getStyle("ha", "marginTop")) will show "auto" in IE and an empty string in Firefox. If I add a style for <p> as margin: 10px, then IE will show 10px and Firefox will not show anything. |
#5
| |||
| |||
|
|
On Mar 17, 4:18 pm, Jeremy <jer... (AT) pinacol (DOT) com> wrote: Seehttp://www.quirksmode.org/dom/getstyles.htmlfor a useful cross-browserish method of getting the current style of an element. thanks for the tip. so function getStyle(el,styleProp) { var x = document.getElementById(el); if (x.currentStyle) var y = x.currentStyle[styleProp]; else if (window.getComputedStyle) var y = document.defaultView.getComputedStyle(x,null).getP ropertyValue(styleProp); return y; } alert(getStyle("ha", "marginTop")) will show "auto" in IE and an empty string in Firefox. If I add a style for <p> as margin: 10px, then IE will show 10px and Firefox will not show anything. |
#6
| |||
| |||
|
|
You really want getStyle("ha", "margin-top"). This will work in both FF and IE. If IE gives you "auto" rather than useful information, I'm afraid I can't help you find the actual value of the default margin. |
#7
| |||
| |||
|
|
The <p> is suggested in CSS Spec 2.1 to have a margin of 1.12em, and in Spec 2.0, to have 1.33em... But looks like Firefox and Safari both use 1em for it. And IE use something less... maybe 0.5em |
|
I wonder if there is a way to find out how the <p> is defined as a default value in your browser? |
|
One way might be to use javascript, but alert(document.getElementById("ha").style.margin_t op) alert(document.getElementById("ha").style.margin) |
![]() |
| Thread Tools | |
| Display Modes | |
| |