【发布时间】:2023-03-11 12:06:01
【问题描述】:
虽然我用下面的代码集实现了同样的效果:
const PyramidChart = () => {
return (
<div className="d-flex flex-column align-items-center pyramid_wrap">
<div className="category_one">
<h6>2</h6>
</div>
<div className="category_two">
<h6>8</h6>
</div>
<div className="category_three">
<h6>11</h6>
</div>
<div className="category_four">
<h6>16</h6>
</div>
</div>
);
};
ReactDOM.render(
<PyramidChart />,
document.getElementById('root')
);
.pyramid_wrap {
height: 100%;
text-align: center;
}
.category_one {
width: 70px;
height: 30px;
border-left: 35px solid transparent;
border-right: 35px solid transparent;
border-bottom: 50px solid tomato;
}
.category_two {
width: 116px;
height: 30px;
border-left: 22px solid transparent;
border-right: 22px solid transparent;
border-bottom: 28px solid orange;
}
.category_three {
width: 162px;
height: 30px;
border-left: 22px solid transparent;
border-right: 22px solid transparent;
border-bottom: 28px solid cyan;
}
.category_four {
width: 208px;
height: 30px;
border-left: 22px solid transparent;
border-right: 22px solid transparent;
border-bottom: 28px solid teal;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.4/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.4/umd/react-dom.production.min.js"></script>
<div id="root"></div>
得到了这样的东西:
但我无法解决的问题是将顶级金字塔区域中的文本对齐到中心。它总是与它对齐的位置不同步。
感谢任何帮助纠正这个问题:)
【问题讨论】:
-
您实际上可以使用
<span>标签而不是<h1>,然后将css 应用于span 标签。<h1>。<span>也是一个内联元素。 -
只有在使用reactjs的情况下,这个html和css如何? :)
-
@bubble-cord : 为每个新层堆叠单独的 CSS 设置可能会变得乏味,我宁愿建议将该部分委托给 React 并在a bit more flexible way中解决问题
标签: javascript html css reactjs