简体   繁体   English

css 样式无法应用于本机反应

[英]css styles are not able to apply in react native

I am showing some popup view which will display two texts over image.我正在展示一些弹出视图,它将在图像上显示两个文本。 So, For that I am trying to setting css in strings.所以,为此我试图在字符串中设置 css。 But, Text is coming in bottom of the image.但是,文本出现在图像的底部。

And I am using fusion charts library for loading graph, Once user taps on the graph lines, I am showing some popup (tooltip).我正在使用融合图表库来加载图形,一旦用户点击图形线,我就会显示一些弹出窗口(工具提示)。 That toolTip text here I am trying to customising according to my requirement此处的 toolTip 文本我正在尝试根据我的要求进行自定义

  toolText: '<div style={{  position: relative; text-align: center; color: white;}}><div><img height="50" width="50" src="http://www.pngpix.com/wp-content/uploads/2016/10/PNGPIX-COM-Mickey-Mouse-PNG-Transparent-Image-1-500x575.png"></img><div style={{ position: absolute; top: 2px; left: 8px; }}>Sample Text1<div><div style={{ position: absolute; top: 10px; left: 16px; }}>Sample Text2</div></div>',

And the output is follows输出如下

在此处输入图片说明

Any suggestions, I want to display text top of the view.任何建议,我想在视图顶部显示文本。

From my understanding, React/React Native requires camel-casing for selector names to be recognizable.根据我的理解,React/React Native 需要驼峰式大小写才能使选择器名称可识别。

Reference: Inline Styles |参考:内联样式 | React反应


Also, your html/css should be formatted similar to the following to received desired overlay effect.此外,您的 html/css 格式应类似于以下内容,以获得所需的叠加效果。

<div style="position: relative;">
    <img>
    <div style="position: absolute;"></div>
    <div style="position: absolute;"></div>
</div>

Reference: CSS Layout - The position Property参考: CSS 布局 - 位置属性

Use position: 'absolute' and top , right , bottom and left to position your Text使用position: 'absolute'top , right , bottomleft来定位你的Text

export default class ToolText extends Component {
  render() {
    return (
      <View style={styles.toolTextContainer}>
        <Image
          style={styles.image}
          source={{
            uri:
              'http://www.pngpix.com/wp-content/uploads/2016/10/PNGPIX-COM-Mickey-Mouse-PNG-Transparent-Image-1-500x575.png',
          }}
        />
        <Text style={styles.text1}>Sample Text 1</Text>
        <Text style={styles.text2}>Sample Text 2</Text>
      </View>
    );
  }
}

styles样式

text1: {
  position: 'absolute',
  top: 2, 
  left: 8,
},
text2: {
  position: 'absolute',
  top: 12,
  left: 16,
},
toolTextContainer: {
  position: 'relative',
  color: 'white',
  justifyContent: 'center',
},
image: {
  width: 50,
  height: 50,
},

Demo演示

Finally, I have found solution after done some R&D, Instead of image I set colour for that.最后,我在完成一些研发后找到了解决方案,我为此设置了颜色而不是图像。

Hope this will help someone in future.希望这会在将来对某人有所帮助。

  toolText: `<div style="border-top-color: 200px solid #somecolor; margin-right: 2px; background-color:#fff display:outer-block; width:auto; height:60px;"><span><text style="font-size: 12px; margin-left:4px; font-weight: bold;  color:#003A69; margin-top:10px; display:inline-block;"> Sample Text1</text></span>{br}<span><text style="font-size: 12px; color:#003A69; margin-left:4px; font-weight: bold; margin-top:2px; display:inline-block;">Sample Text2</text></span>{br}</div>`,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM