我有下一个代码:
<button onClick={this.openModal}>[{this.props.defaultValue}]</button>
从中获取的文本
[{this.props.defaultValue}]
始终居中。有没有办法让它向左对齐?
这是我目前正在尝试的:
const bstyle = {
textAlign:'left',
color: 'white'
};
const {open} = this.state;
return (
<div>
<button style={bstyle} onClick={this.onOpenModal}>[{this.props.defaultValue}]</button>
....
没有结果。 :-( 我可以看到按钮与左侧对齐。但是它的文字居中。
最佳答案
你可以为此设置 'text-align'
<button onClick={this.openModal} style="text-align: left;">[{this.props.defaultValue}]</button>
或者你可以定义一个类
并设置它的CSS
<button onClick={this.openModal} class="text-left">[{this.props.defaultValue}]</button>
<style>
.text-left{
text-align: left;
}
</style>
关于css - 将按钮的文本向左对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44340607/