JS - appendChild()并正确继承css - >余量

时间:2018-01-03 19:29:00

标签: javascript html css

有没有人注意到在实现appendChild方法插入元素时,边距中缺少几个像素?

对于istance:

   <script>
    function tryit(){
        var d = document.getElementsByTagName("div")[0],
        e   = document.getElementsByClassName("try");

        d.appendChild(e[0].cloneNode(true));
        d.removeChild(e[0]);
    }
    </script>
    <style>
    body{
        background-color:red;
    }
    div{
        padding:40px;
    }
    .try{
        margin:20px;
        padding:10px;
        background-color:white;
        border:5px solid black;
        color:blue;
    }
    </style>
    <button onclick="tryit()">try</button>
    <div>
    <span class="try">hello</span>
    <span class="try">hello</span>
    <span class="try">hello</span>
    <span class="try">hello</span>
    </div>

0 个答案:

没有答案