Challenge - 5 Problems
Margin, Padding & Border Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Understanding margin effect on layout
Given the following React Native code, what will be the space between the blue box and the red box?
React Native
import React from 'react'; import { View } from 'react-native'; export default function App() { return ( <View style={{ flexDirection: 'row' }}> <View style={{ width: 50, height: 50, backgroundColor: 'blue', marginRight: 20 }} /> <View style={{ width: 50, height: 50, backgroundColor: 'red' }} /> </View> ); }
Attempts:
2 left
💡 Hint
Margin adds space outside the component's border.
✗ Incorrect
The marginRight: 20 on the blue box adds 20 pixels of space to its right side, pushing the red box away by 20 pixels.
❓ ui_behavior
intermediate2:00remaining
Padding effect inside a component
What will be the visible effect of the padding in this React Native component?
React Native
import React from 'react'; import { View, Text } from 'react-native'; export default function App() { return ( <View style={{ backgroundColor: 'yellow', padding: 15 }}> <Text>Text inside padded box</Text> </View> ); }
Attempts:
2 left
💡 Hint
Padding adds space inside the component's border.
✗ Incorrect
Padding creates space inside the yellow box around the text, so the text is not touching the edges.
❓ ui_behavior
advanced2:00remaining
Border width and color effect
What will be the visible border around the green box in this React Native code?
React Native
import React from 'react'; import { View } from 'react-native'; export default function App() { return ( <View style={{ width: 100, height: 100, backgroundColor: 'green', borderWidth: 5, borderColor: 'black' }} /> ); }
Attempts:
2 left
💡 Hint
Border width and color define the visible border thickness and color.
✗ Incorrect
Setting borderWidth: 5 and borderColor: 'black' creates a black border 5 pixels thick around the green box.
❓ lifecycle
advanced2:00remaining
Effect of margin and padding on touchable area
In React Native, if a
TouchableOpacity has margin and padding, which area responds to touch?React Native
import React from 'react'; import { TouchableOpacity, Text } from 'react-native'; export default function App() { return ( <TouchableOpacity style={{ margin: 20, padding: 10, backgroundColor: 'lightblue' }}> <Text>Press me</Text> </TouchableOpacity> ); }
Attempts:
2 left
💡 Hint
Margin is outside the component's touchable area; padding is inside.
✗ Incorrect
Touchable area includes the component plus its padding. Margin is outside and does not respond to touch.
🔧 Debug
expert2:00remaining
Why is the border not visible?
A developer wrote this code but the border does not show. What is the reason?
React Native
import React from 'react'; import { View } from 'react-native'; export default function App() { return ( <View style={{ width: 100, height: 100, backgroundColor: 'white', borderColor: 'red' }} /> ); }
Attempts:
2 left
💡 Hint
Border color alone does not create a visible border without width.
✗ Incorrect
Without borderWidth, the border is not drawn even if borderColor is set.