首页 > 解决方案 > 为什么 textAlign 或 align 在 reactjs 中不起作用?

问题描述

我已经尝试通过我的 App.css 文件来完成它,然后我尝试了内联样式,但它仍然不会对齐屏幕中心的按钮。

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

class Body extends Component {
    btn = {
        
    }

    render() {
        return (
            <div>
                <button style={{textAlign:'center'}}>Get Started</button>
            </div>
        );
    }
}

export default Body;

标签: reactjs

解决方案


我遇到了一个类似的问题,当使用 'semantic-ui-react' Header 组件时,内联样式不起作用。但是在将 Header 组件包装在 a 中并在textAlign: 'center'其上应用样式之后,它就起作用了。


推荐阅读