美文网首页
标签的箭头排列

标签的箭头排列

作者: 心存美好 | 来源:发表于2022-03-16 15:21 被阅读0次

    标签的箭头排列

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            * {
                margin: 0;
                padding: 0;
            }
    
            #box {
                position: relative;
                width: 250px;
                height: 250px;
                border: 1px dashed black;
                margin: 50px auto;
            }
    
            #box div {
                position: absolute;
                width: 50px;
                height: 50px;
                background-color: skyblue;
    
                text-align: center;
                font: bold 20px/50px 'Arial';
            }
        </style>
    </head>
    
    <body>
        <div id="box">
        </div>
    
        <script>
            //获取元素
            let oBox = document.getElementById('box')
            //信号量
            let height = 50;
            let len = 6;
            let middle = parseInt(len / 2)
            for (let i = 0; i < len; i++) {//创建div标签
                let oDiv = document.createElement('div')
                oDiv.innerHTML = i;
                let index = i;
    
                if (i >= middle) {
                    index = len - 1 - i;
                    console.log(index)
                }
                oDiv.style.cssText = `left:${index * height}px;top:${i * height}px`;//整体加样式
                oBox.appendChild(oDiv)
            }
        </script>
    
    </body>
    
    </html>
    

    相关文章

      网友评论

          本文标题:标签的箭头排列

          本文链接:https://www.haomeiwen.com/subject/cmypdrtx.html