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>