在 HTML/CSS 中,如果您希望绝对定位的元素比其父元素扩展得更宽以将其所有文本放在一行中,您可以使用 white-space: no-wrap
.parent {
position: relative;
width: 100px;
}
// text content of this node is wider than 100px
.child {
position: absolute;
white-space: nowrap;
}
子元素将增长到足以容纳一行中的所有文本。
Text
没有办法做到这一点React Native 中的组件。您必须指定一个固定的数字宽度,否则 Text 组件将在父宽度处最大化。有办法吗?
最佳答案
发现答案很简单。
可以使用 <Text>
指定文本换行组件的内置接口(interface) numberOfLines
, 而不是 CSS。
<Text numberOfLines={1}>Foobar</Text>
可以找到这方面的文档 here .
关于react-native - react native 空白 : nowrap width for absolutely positioned Text node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46698137/