【问题标题】:textDecoration: line-through not working in React Native styled componenttextDecoration:直通在 React Native 样式的组件中不起作用
【发布时间】:2021-01-05 05:37:39
【问题描述】:

我创建了一个样式化组件

const StrikeThrough = styled(StandardText)`
    textDecoration: line-through;
`;

并用孩子调用它,类似于<StrikeThrough>Write text here</StrikeThrough>,但呈现的文本没有这种装饰。为什么会这样?

编辑:我尝试过的其他方法不起作用

const StrikeThrough = styled(StandardText)`
    textDecorationLine: line-through;
    textDecorationStyle: solid;
`;
const StrikeThrough = styled(StandardText)`
    text-decoration: line-through;
`;

编辑: 要回答我自己的问题,看来我必须在 Text 组件上执行此操作,并且无法在我的样式组件之上创建样式组件。

【问题讨论】:

    标签: css react-native mobile styles


    【解决方案1】:

    使用text-decoration 代替textDecoration

    【讨论】:

      【解决方案2】:

      使用text-decoration: line-through;

      您也可以使用text-decoration-color: red 设置线条样式

      【讨论】:

        【解决方案3】:

        您正在使用样式化组件,因此请使用 text-decoration 而不是 textDecoration 并使用点而不是括号:

        const StrikeThrough = styled.Text`
            text-decoration: line-through;
        `;
        

        【讨论】:

          猜你喜欢
          • 2019-01-12
          • 2017-12-30
          • 2022-01-01
          • 2020-11-03
          • 2020-05-11
          • 2019-06-23
          • 2021-01-23
          • 1970-01-01
          相关资源
          最近更新 更多