css - 使用 React Native 模拟内联 block

标签 css react-native flexbox

有人知道如何用React Native模拟display: inline-block吗?

基本上我想添加一个 display: inline-block 到创建的样式中。

示例:

enter image description here

我的目的是避免当前面的消息太长时将上面的“3 天前”分成两行。

谢谢!

[编辑] 这是我的 React Native 代码:

<View style={styles.contentContainer}>
    <Text>
        <Text style={styles.content}>{notification.content}</Text>
        <Text style={styles.created}>   {moment(notification.created, "YYYY-MM-DD[T]hh:mm:ss").subtract(n, 'hours').fromNow()}</Text>
    </Text>
</View>

下面是相关的 CSS 对应:

contentContainer: {
    flex: 1,
},
content: {
    textAlign: 'left',
    fontSize: 14,
},
created: {
    textAlign: 'left',
    fontSize: 10,
    color: '#777777',
},

最佳答案

主要更改是将 flexWrap: 'nowrap' 添加到 created 样式。

工作示例:https://rnplay.org/apps/RgpZ5w

关于css - 使用 React Native 模拟内联 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37619261/

相关文章:

css - Flexbox 调整子宽度大小应仅更改下一个同级宽度

javascript - Flexbox 图像库和单个图像位置

javascript - 如何连接数组索引以根据索引更改组件的样式?

html - 如何使一个 block 在 flexbox 显示中固定和 float ?

css - 有没有办法覆盖 HTML5 表单验证消息的默认 CSS

相当于 "font size+2"的 HTML 样式标签

html - 正确固定位置,以便页面上 4 个元素中的 3 个不会随着滚动而移动

javascript - 带垂直滚动条的div滚动条 "main"

ios - react native : detect if UIVisualEffectView is supported

javascript - 我可以在 react 状态中有一个功能吗?