标签的箭头排列

2022-03-16  本文已影响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>
上一篇下一篇

猜你喜欢

热点阅读