
给容器添加行号
在react组件中创建很多小方格后,由于项目的需要,有时我们需要给容器添加行号。
对于如何设计,我们提出了一种解决方案。
左侧的行号索引设置为绝对定位,右侧的小方块设置为相对定位,而它们的父元素设置为相对定位并隐藏溢出。
具体代码如下:
// index.js
import react from "react";
import reactdom from "react-dom";
import "./styles.css";
function app() {
const itemdata = new array(500).fill(0);
const indexdata = new array(20).fill(0);
return (
{indexdata.map((item, index) => (
{index}
))}
{itemdata.map((item, index) => (
))}
);
}
const rootelement = document.getelementbyid("root");
reactdom.render( , rootelement);// styles.css
.App {
font-family: sans-serif;
text-align: center;
overflow: hidden;
position: relative;
}
.left-box {
position: absolute;
left: 0;
top: 0;
width: 19px;
overflow: hidden;
}
.right-box {
margin-left: 19px;
}










