【问题标题】:How do I get block to align center?如何让块对齐中心?
【发布时间】:2020-09-12 10:42:22
【问题描述】:

如您所见,我正在尝试使用“margin:'auto'”将 div 与中心对齐。但它似乎不起作用。

import React, { Component } from 'react';
import './CenterBlock.css';

class CenterBlock extends Component {
    state = {
        styling: {
            margin: 'auto'
        }
    }

    render() {
        return (
            <div className="center__block__container" style={this.state.styling}>
                <div className="block">
                    <h1>Generate Password</h1>
                </div>
            </div>
        );
    }
}

export default CenterBlock;

【问题讨论】:

标签: javascript html reactjs


【解决方案1】:

我建议改为这样做。如果您不必支持旧浏览器

<div style={{display: 'flex', justifyContent: 'center'}}>
  <div>This content will be centered</div>
</div>

【讨论】:

    猜你喜欢
    • 2017-10-30
    • 2011-01-17
    • 2014-12-26
    • 2021-04-11
    • 1970-01-01
    • 2013-11-27
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    相关资源
    最近更新 更多