简体   繁体   English

如何让块对齐中心?

[英]How do I get block to align center?

As you can see I am trying to align the div to the center using "margin: 'auto'".如您所见,我正在尝试使用“margin: 'auto'”将 div 与中心对齐。 But it doesn't seem to be working.但它似乎不起作用。

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;

I would suggest doing something like this instead.If you don't have to support old browsers我建议做这样的事情,如果你不必支持旧浏览器

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM