Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 对齐按钮';s文本在左边_Css_Reactjs_Ecmascript 6 - Fatal编程技术网

Css 对齐按钮';s文本在左边

Css 对齐按钮';s文本在左边,css,reactjs,ecmascript-6,Css,Reactjs,Ecmascript 6,我有下一个代码: <button onClick={this.openModal}>[{this.props.defaultValue}]</button> 始终居中。有没有办法让它向左对齐 这就是我目前正在尝试的: const bstyle = { textAlign:'left', color: 'white' }; const {open} = this.state; return (

我有下一个代码:

<button onClick={this.openModal}>[{this.props.defaultValue}]</button>
始终居中。有没有办法让它向左对齐

这就是我目前正在尝试的:

const bstyle = { 
        textAlign:'left',
        color: 'white'
     };
    const {open} = this.state;
    return (
            <div>
            <button style={bstyle} onClick={this.onOpenModal}>[{this.props.defaultValue}]</button>

 ....
constbstyle={
textAlign:“左”,
颜色:“白色”
};
const{open}=this.state;
返回(
[{this.props.defaultValue}]
....
没有结果-(
我可以看到按钮向左对齐。但是它的文本居中。

您可以为此设置“文本对齐”

<button onClick={this.openModal} style="text-align: left;">[{this.props.defaultValue}]</button>

样式需要一个
对象

在React中,内联样式不是指定为字符串,而是 使用其键为的camelCased版本的对象指定 样式名称,其值为样式的值,通常为 绳子

左侧填充设置为
0px

这样写:

<button onClick={this.openModal} style={{paddingLeft:'0px'}}>{this.props.defaultValue}</button>
{this.props.defaultValue}
选中此项:

var-App=()=>{
返回(
你好,世界
)
}
ReactDOM.render(,document.getElementById('app'))


从我得到的第一个:未捕获错误:
style
prop需要从样式属性到值的映射,而不是字符串。例如,当使用JSX时,style={{marginRight:spating+'em'}}。您可以使用
style={{paddingLeft:'0px'}
style={{textAlign:'left'}
或两者都可以使用
<button onClick={this.openModal} class="text-left">[{this.props.defaultValue}]</button>

<style>
    .text-left{
        text-align: left;
    }
</style>
<button onClick={this.openModal} style={{paddingLeft:'0px'}}>{this.props.defaultValue}</button>