我使用的是reactjs-popup库中的一个弹出模式组件。我想将图表图像(一个图像中的三个图表)放在弹出窗口的中心,但是像align-self这样的属性似乎不适合我。我还能尝试什么呢?
export default () => (
<Popup
trigger={<button className="button"> Guide </button>}
modal
nested
>
{(close: any) => (
<div className="modal">
<button className="close" onClick={close}>
×
</button>
<div className="header"> Guide </div>
<div className="content">
{' '}
{/* <img src={chart} alt="charts" className="charts"/> */}
<img src={img} alt="charts" className="charts" />
What is overfitting?
<br />
What is underfitting?
This example demonstrates the problems of underfitting and overfitting and how we can use linear regression with polynomial features to approximate nonlinear functions.
</div>
<div className="actions">
</div>
</div>
)}
</Popup>
);它看起来是这样的:

css
.modal {
font-size: 12px;
border-color: black;
border-style: solid;
}
.modal > .content {
width: 100%;
padding: 10px 5px;
background-color: white;
}
.modal > .actions {
width: 100%;
padding: 10px 5px;
margin: auto;
text-align: center;
background-color: white;
}
.charts {
align-self: center;
}我还想把文本what's overfitting移到中间的图片下面。
发布于 2021-03-19 08:13:53
将display: flex;添加到.modal > content的css类中。此外,为了使项目居中对齐,您需要在同一个css类中设置flex-direction: column;和align-items: center。
我还建议您在本MDN article中阅读有关flex对齐的概念。
https://stackoverflow.com/questions/66700845
复制相似问题