【问题标题】:react-Native css styling with multiple arguments具有多个参数的 react-Native css 样式
【发布时间】:2020-07-09 19:45:14
【问题描述】:

如何像这样在 react-native css 中设置样式? 边框宽度:5px 5px 5px 5px

我试过了: 边框宽度:{5,5,5,5} 和 边框宽度:'5px 5px 5px 5px' 但没有运气

【问题讨论】:

    标签: css reactjs react-native


    【解决方案1】:

    试试:

    borderBottomWidth:5 borderTopWidth:5

    等等

    【讨论】:

    • 非常感谢。所以这个问题实际上是希望回答一个更大的问题。我正在尝试使用像 transform: translate(x,y) 这样的样式怎么做?
    • 在这里查看 react native 文档:linktransform([{ skewX: '45deg' }]);
    【解决方案2】:

    react-native 中,您不能使用border-width: 5px 5px 5px 5px。取而代之的是,您必须使用以下属性。

     1. borderTopWidth, 
     2. borderBottomWidth,  
     3. borderLeftWidth
     4. borderRightWidth
    

    但如果你想实现类似borderWidth 的东西,那么你可以编写自己的函数。

    function borderWidth(top,right,bottom,left){
      let styles;
      styles['borderTopWidth'] = top
      styles['borderRightWidth'] = right
      return styles
    }
    

    那么在Stylesheet就可以使用了

    container : {
        ...borderWidth(5,5,5,5)
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-18
      • 2020-11-02
      • 1970-01-01
      • 2018-01-24
      • 2021-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多