[英]css styles are not able to apply in react native
我正在展示一些弹出视图,它将在图像上显示两个文本。 所以,为此我试图在字符串中设置 css。 但是,文本出现在图像的底部。
我正在使用融合图表库来加载图形,一旦用户点击图形线,我就会显示一些弹出窗口(工具提示)。 此处的 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>',
输出如下
任何建议,我想在视图顶部显示文本。
根据我的理解,React/React Native 需要驼峰式大小写才能使选择器名称可识别。
此外,您的 html/css 格式应类似于以下内容,以获得所需的叠加效果。
<div style="position: relative;">
<img>
<div style="position: absolute;"></div>
<div style="position: absolute;"></div>
</div>
参考: CSS 布局 - 位置属性
使用position: 'absolute'
和top
, right
, bottom
和left
来定位你的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>
);
}
}
样式
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,
},
最后,我在完成一些研发后找到了解决方案,我为此设置了颜色而不是图像。
希望这会在将来对某人有所帮助。
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.