this is code by css at id works fine:
border-bottom: 100px solid #0000ff80;
border-right: 50px solid transparent;
height: 0;
width: 100px;
<div id="trapezoid"></div>
but my code on react-native doesn't work:
<View style={{width:100,height:0,borderBottomWidth:100,borderBottomColor:'#000',borderLeftWidth:0,borderRightWidth:50,borderRightColor:'#000'}}>
</View>
this is code by css at id works fine:
border-bottom: 100px solid #0000ff80;
border-right: 50px solid transparent;
height: 0;
width: 100px;
<div id="trapezoid"></div>
but my code on react-native doesn't work:
<View style={{width:100,height:0,borderBottomWidth:100,borderBottomColor:'#000',borderLeftWidth:0,borderRightWidth:50,borderRightColor:'#000'}}>
</View>
Share
Improve this question
asked Feb 12, 2019 at 10:00
S.M_EmamianS.M_Emamian
17.4k40 gold badges154 silver badges273 bronze badges
3 Answers
Reset to default 4try this out
var Trapezoid = React.createClass({
render: function() {
return (
<View style={styles.trapezoid} />
)
}
})
trapezoid: {
width: 200,
height: 0,
borderBottomWidth: 100,
borderBottomColor: 'red',
borderLeftWidth: 50,
borderLeftColor: 'transparent',
borderRightWidth: 50,
borderRightColor: 'transparent',
borderStyle: 'solid'
}
for more such shapes checkout https://codedaily.io/tutorials/22/The-Shapes-of-React-Native
You can achieve it by a rectangle and a triangle in a row.
<View style={{ flexDirection: 'row' }}>
<View style={styles.rectangle} />
<View style={[styles.triangle, styles.triangleCornerBottomLeft]} />
</View>
const styles = StyleSheet.create({
rectangle: { width: 100, height: 100, backgroundColor: 'red' },
triangle: {
width: 0,
height: 0,
backgroundColor: 'transparent',
borderStyle: 'solid',
borderRightWidth: 100,
borderTopWidth: 100,
borderRightColor: 'transparent',
borderTopColor: 'red'
},
triangleCornerBottomLeft: {
transform: [
{rotate: '270deg'}
]
},
});
you can achieve it by rotating it in x-axis
<View style={styles.container}>
<View style={styles.trapezium}></View>
</View>
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'gray',
},
trapezium: {
height: 300,
width: 200,
backgroundColor: 'white',
transform: [{rotateX: '60deg'}],
},
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744992952a4605016.html
评论列表(0条)