div中间十字线

本文介绍了一种使用CSS实现商品列表无缝布局的方法。通过调整元素的边界和间距,使得列表中的每个商品项紧密排列,同时保持良好的视觉效果。
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>1</title>
       <style>
        *{
            padding: 0;
            margin: 0;
        }
        div{
            overflow: hidden;
            width: 160px;
            margin: 50px;
        }
        ul{
            list-style: none;
        }
        li{
            float: left;
            height: 100px;
            width: 50px;       
            border-left:1px solid red;          /*设置左边框*/
            border-bottom: 1px solid red;         /*设置下边框*/
            margin-left: -1px;
            /*-1后在父容器下面了,所以看不到*/
            margin-bottom: -1px;   
        }
    </style>
    </head>
<body>


    <div>
        <ul>
            <li>商品</li>
            <li>商品</li>
            <li>商品</li>
            <li>商品</li>
            <li>商品</li>
            <li>商品</li>
        </ul>
    </div>

</script>

</body>
</html>
``` <!DOCTYPE html> <html> <head> <title></title> <style> body { background-color: #000; margin: 0; height: 100vh; display: flex; justify-content: center; align-items: center; } #centerCrosshair { position: absolute; width: 20px; /* 十字线宽度 */ height: 20px; /* 十字线高度 */ top: 50%; left: 50%; transform: translate(-50%, -50%); } /* 使用伪元素创建水平和垂直线 */ #centerCrosshair::before, #centerCrosshair::after { content: ''; position: absolute; background-color: red; } /* 水平线 */ #centerCrosshair::before { width: 100px; /* 水平线长度 */ height: 3px; /* 水平线粗细 */ left: 50%; transform: translateX(-55%); } /* 垂直线 */ #centerCrosshair::after { width: 3px; /* 垂直线粗细 */ height: 100px; /* 垂直线长度 */ top: 50%; transform: translateY(-55%); } #movableCrosshair { position: absolute; width: 0; /* 容器尺寸清零 */ height: 0; transform: translate(-50%, -50%); /* 中心点对齐 */ top: calc(50% + 20px); /* 初始位置 */ left: calc(50% + 20px); } /* 水平线 */ #movableCrosshair::before { content: ''; position: absolute; width: 100px; /* 十字线水平长度 */ height: 2px; /* 线粗 */ background: #00f7ff; transform: translateX(-45%); /* 向左偏移一半宽度 */ } /* 垂直线 */ #movableCrosshair::after { content: ''; position: absolute; width: 2px; /* 线粗 */ height: 100px; /* 十字线垂直长度 */ background: #00f7ff; transform: translateY(-45%); /* 向上偏移一半高度 */ } </style> </head> <body> <div id="centerCrosshair"></div> <div id="movableCrosshair"></div> <script> document.addEventListener('keydown', function(event){ const crosshair = document.getElementById('movableCrosshair'); let style = window.getComputedStyle(crosshair); let topValue = parseInt(style.getPropertyValue('top')); let leftValue = parseInt(style.getPropertyValue('left')); switch (event.key) { case 'ArrowUp': crosshair.style.top = `${topValue - 1}px`; break; case 'ArrowDown': crosshair.style.top = `${topValue + 1}px`; break; case 'ArrowLeft': crosshair.style.left = `${leftValue - 1}px`; break; case 'ArrowRight': crosshair.style.left = `${leftValue + 1}px`; break; } }); </script> </body> </html>```给movableCrosshair十字线加上刻度,将优化后的代码直接整体输出
03-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值