如何为应用Bulma button样式的textarea恢复换行功能
直接给你的textarea添加自定义样式,覆盖.button类的限制即可,完全不需要用Sass:
- 第一步,给textarea保留现有Bulma类的同时,新增一个自定义类(比如
textarea-multiline):
<textarea class="button is-outlined has-background-black has-text-light has-text-left textarea-multiline" placeholder="Placeholder Text"></textarea>
- 第二步,添加一段自定义CSS(内联或外部样式表都可以):
.textarea-multiline { white-space: pre-wrap !important; min-height: 100px; /* 可选,给textarea设置最小高度,更适合多行输入 */ }
核心原因是Bulma的.button类强制设置了white-space: nowrap,导致textarea无法换行。用white-space: pre-wrap就能恢复自动换行和手动换行的功能,!important是为了确保样式能覆盖Bulma的原设置。
如果想快速测试,也可以直接用内联样式:
<textarea class="button is-outlined has-background-black has-text-light has-text-left" placeholder="Placeholder Text" style="white-space: pre-wrap;"></textarea>
这样既能保留你想要的深色主题按钮样式,又能让textarea正常支持多行输入。
内容的提问来源于stack exchange,提问作者Sage Hendricks
相关产品推荐
相关产品推荐

