Css 为什么我的内联样式可以工作,但我的样式表不是';你根本不改变密码吗?
我正在用React Native编写导航条。可以将其视为双层——上层是汉堡菜单、标题和搜索图标,第二层由三个可触摸标题组成,用于导航到相关屏幕 当我应用内联样式时,它们会起作用。当我在下面创建和应用样式表时,它们不会。我是编程新手,非常困惑 我的计划是编写一个单独的导航栏,将其分为两行(视图):navbarTop和navbarBottom。我非常希望能够深入了解这样做是否有意义,以及如何解决我的样式问题。非常感谢大家Css 为什么我的内联样式可以工作,但我的样式表不是';你根本不改变密码吗?,css,react-native,react-native-android,Css,React Native,React Native Android,我正在用React Native编写导航条。可以将其视为双层——上层是汉堡菜单、标题和搜索图标,第二层由三个可触摸标题组成,用于导航到相关屏幕 当我应用内联样式时,它们会起作用。当我在下面创建和应用样式表时,它们不会。我是编程新手,非常困惑 我的计划是编写一个单独的导航栏,将其分为两行(视图):navbarTop和navbarBottom。我非常希望能够深入了解这样做是否有意义,以及如何解决我的样式问题。非常感谢大家 import React, { Component } from 'reac
import React, { Component } from 'react';
import { View, Text, StyleSheet, Image, TouchableHighlight } from 'react-native';
import { withNavigation } from 'react-navigation';
class Navbar extends Component {
render() {
return (
<View style={styles.navbarTop}>
<View>
<TouchableHighlight
onPress={() => {
this.props.navigation.openDrawer();
}}
>
<Image
style={{marginBottom: 5}}
source={require('./../../../android/app/src/main/res/drawable/menu.png')}
/>
</TouchableHighlight>
</View>
<View>
<Text
style={{
fontWeight: 'bold',
color: 'white',
fontSize: 20,
marginRight: 70
}}
>
Dashboard
</Text>
</View>
<View>
<Image
style={{marginBottom: 5}}
source={require('./../../../android/app/src/main/res/drawable/search.png')}
/>
</View>
<View style={styles.navbarBottom}>
<View>
<Text
style={{
color: 'white',
fontSize: 15,
marginRight: 70
}}
> RECORDINGS </Text>
</View>
<View>
<Text
style={{
color: 'white',
fontSize: 15,
marginRight: 70
}}
> PATIENTS </Text>
</View>
<View>
<Text
style={{
color: 'white',
fontSize: 15,
marginRight: 70
}}
> DEVICES </Text>
</View>
</View>
</View>
);
}
}
export default withNavigation(Navbar);
const styles = StyleSheet.create({
navbarTop: {
backgroundColor: '#14172B',
padding: 10,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-end',
},
// navbarBottom: {
// }
});
import React,{Component}来自'React';
从“react native”导入{视图、文本、样式表、图像、TouchableHighlight};
从“react navigation”导入{withNavigation};
类导航栏扩展组件{
render(){
返回(
{
this.props.navigation.openDrawer();
}}
>
仪表板
录音
患者
装置
);
}
}
使用导航(导航栏)导出默认值;
const styles=StyleSheet.create({
纳瓦巴托普:{
背景颜色:“#14172B”,
填充:10,
flexDirection:'行',
justifyContent:'之间的空间',
对齐项目:“柔性端”,
},
//海军基地:{
// }
});
行内样式覆盖样式表中的样式
假设有一个样式组件:
<View style = {[styles.demoView,{marginTop:50}]}/>
export default StyleSheet.create({
demoView: {
marginTop:20,
flexDirection: "row",
padding: "10rem",
justifyContent: "space-between",
alignItems: "center",
},
Hi@dereknahman,在CSS中,内联样式比内部和外部CSS具有更高的优先级。这就是为什么你的内联CSS只在这里工作。尝试检查其他CSS是否对您的CSS产生影响。谢谢!你有什么让我的应用程序听样式表的建议吗?创建内联样式,而不是只创建内联样式?答案已经在我发布的答案中了。如果样式是内联的,那么该特定值不会从样式表中调用,而是从内联样式中获取,因为它们具有高优先级。如果答案有用,请接受这样一个事实,即其他面临同样疑问的人可以有一个更清晰的愿景,但样式表中的样式。即使内联样式被完全删除,创建也不会影响我的应用程序的外观,因此内联样式优先于样式表。在这种情况下,创建似乎不是问题您可能做错了什么。共享完整的代码。
import React, { Component } from 'react';
import { View, Text, StyleSheet, Image, TouchableHighlight } from 'react-native';
import { withNavigation } from 'react-navigation';
class Navbar extends Component {
render() {
return (
<View style={styles.navbarTop}>
<TouchableHighlight
onPress={() => { this.props.navigation.openDrawer()}}>
<Image style={{marginBottom: 5}}
source={require('./../../../android/app/src/main/res/drawable/menu.png')}
/>
</TouchableHighlight>
<Text style={{fontWeight: 'bold',color: 'white',fontSize: 20,marginRight: 70}}>
Dashboard
</Text>
<Image
style={{marginBottom: 5}}
source={require('./../../../android/app/src/main/res/drawable/search.png')}
/>
<View style={styles.navbarBottom}>
<Text style={styles.navBarText}> RECORDINGS </Text>
<Text style={styles.navBarText}> PATIENTS </Text>
<Text style={styles.navBarText}> DEVICES </Text>
</View>
</View>
);
}
}
export default withNavigation(Navbar);
const styles = StyleSheet.create({
navbarTop: {
backgroundColor: '#14172B',
padding: 10,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-end',
},
// navbarBottom: {
// }
navBarText:{
color: 'white',
fontSize: 15,
marginRight: 70
}
});