Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

default body margin, I didn't set, but it does have default value 8px, how can get this value?

    <style type="text/css">
        fieldset {
            border: solid 1px orange
        }
        .label {
            font-family: Arial;
            font-size: 12px;
            font-weight: bold
        }
        .groupName {
            font-family: Segoe UI;
            font-size: 16px;
            color: Gray
        }
    </style>

    <script type="text/javascript" src="libs/json2.js"></script>
    <script type="text/javascript" src="libs/jquery.js"></script>
    <script type="text/javascript" src="libs/sap.common.globalization.js"></script>
    <script type="text/javascript" src="libs/sap.riv.base.js" base-url="modules/"></script>
    <script type="text/javascript" src="modules/main.js"></script>
    <script type="text/javascript" src="libs/sap.riv.themes.js"></script>
</head>
<body>
    <div id="chart" style="width: 600px; height: 400px; background-color: #ffffff"><div id="0" style="position: absolute; font-size: 10px; box-sizing: border-box; overflow-x: visible; overflow-y: visible; left: 8px; top: 8px; width: 600px; height: 400px; ">` 

In chrome I can see

 body{
 display:block;
 margin: 8px;
}

I use document.getElementsByTagName('body').style but get nothing.

my first div located at top&left: 8px of the html body.

But it does have margin, how could I get this default margin value?

like image 546
richard sun Avatar asked Oct 24 '25 17:10

richard sun


1 Answers

document.getElementsByTagName('body') returns an array on success.
To get rid of the margin in the body use normal css

body{
    margin: 0;
}

EDIT: I found this function that can give you the styles of elements on quirksmode

function getStyle(el,styleProp)
{
    if (el.currentStyle)
        var y = el.currentStyle[styleProp];
    else if (document.defaultView && document.defaultView.getComputedStyle)
        var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
    return y;
}

Fiddle1 Fiddle2

like image 120
Musa Avatar answered Oct 26 '25 08:10

Musa