Bird
Raised Fist0
React Nativemobile~20 mins

Margin, padding, border in React Native - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Margin, Padding & Border Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2: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>
  );
}
AThere will be a 20-pixel space between the blue and red boxes.
BThere will be a 20-pixel space inside the blue box around its content.
CThe boxes will touch each other with no space.
DThe red box will have a 20-pixel space around it.
Attempts:
2 left
💡 Hint
Margin adds space outside the component's border.
❓ ui_behavior
intermediate
2: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>
  );
}
AThe yellow box will shrink by 15 pixels on each side.
BThe yellow box will have 15 pixels of space outside its border.
CThe text will be 15 pixels larger in font size.
DThe text will have 15 pixels of space inside the yellow box around it.
Attempts:
2 left
💡 Hint
Padding adds space inside the component's border.
❓ ui_behavior
advanced
2: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' }} />
  );
}
ANo border will appear because borderColor is ignored without borderStyle.
BA black border 5 pixels thick will appear around the green box.
CA green border 5 pixels thick will appear around the box.
DA black border 1 pixel thick will appear around the green box.
Attempts:
2 left
💡 Hint
Border width and color define the visible border thickness and color.
❓ lifecycle
advanced
2: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>
  );
}
ANeither margin nor padding areas respond to touch.
BBoth margin and padding areas respond to touch.
COnly the area inside the padding responds to touch; margin area does not.
DOnly the margin area responds to touch; padding area does not.
Attempts:
2 left
💡 Hint
Margin is outside the component's touchable area; padding is inside.
🔧 Debug
expert
2: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' }} />
  );
}
AThe borderWidth is missing, so the border is not drawn.
BThe borderColor 'red' is invalid and ignored.
CThe backgroundColor 'white' hides the border.
DThe View needs a borderStyle set to 'solid' to show the border.
Attempts:
2 left
💡 Hint
Border color alone does not create a visible border without width.

Practice

(1/5)
1. What does padding do in a React Native style?
easy
A. Adds space inside the element, between content and border
B. Adds space outside the element, between element and neighbors
C. Draws a line around the element
D. Changes the background color of the element

Solution

  1. Step 1: Understand padding concept

    Padding adds space inside the element, pushing content away from the edges.
  2. Step 2: Compare with margin and border

    Margin adds space outside the element; border draws a line around it.
  3. Final Answer:

    Adds space inside the element, between content and border -> Option A
  4. Quick Check:

    Padding = inside space [OK]
Hint: Padding is inside space; margin is outside space [OK]
Common Mistakes:
  • Confusing padding with margin
  • Thinking border adds space
  • Mixing padding with background color
2. Which of the following is the correct way to add a 10 pixel margin to all sides of a View in React Native?
easy
A. { padding: 10 }
B. { marginLeft: 10, padding: 10 }
C. { borderWidth: 10 }
D. { margin: 10 }

Solution

  1. Step 1: Identify margin syntax

    To add margin on all sides, use margin: 10.
  2. Step 2: Check other options

    Padding adds inner space, borderWidth adds border thickness, and marginLeft only adds left margin.
  3. Final Answer:

    { margin: 10 } -> Option D
  4. Quick Check:

    margin: 10 adds margin all sides [OK]
Hint: Use margin: value for all sides margin [OK]
Common Mistakes:
  • Using padding instead of margin
  • Using borderWidth to add space
  • Only setting marginLeft instead of all sides
3. What will be the visible effect of this style on a View?
{
  padding: 20,
  margin: 10,
  borderWidth: 5,
  borderColor: 'red'
}
medium
A. The View has no visible border but has padding and margin
B. The View has 20 pixels space outside, 10 pixels space inside, and no border
C. The View has 10 pixels space outside, 20 pixels space inside, and a 5 pixel red border
D. The View has a 5 pixel blue border with no padding or margin

Solution

  1. Step 1: Analyze padding and margin values

    Padding: 20 adds space inside the View; margin: 10 adds space outside.
  2. Step 2: Analyze border properties

    borderWidth: 5 adds a 5 pixel border; borderColor: 'red' colors it red.
  3. Final Answer:

    The View has 10 pixels space outside, 20 pixels space inside, and a 5 pixel red border -> Option C
  4. Quick Check:

    margin = outside, padding = inside, borderWidth + borderColor = border [OK]
Hint: Margin outside, padding inside, borderWidth + borderColor visible [OK]
Common Mistakes:
  • Mixing padding and margin values
  • Ignoring borderColor effect
  • Assuming borderWidth is padding
4. Identify the error in this style code for adding margin and border:
{
  margin: 15,
  border: '2px solid black'
}
medium
A. Border color must be set separately from borderWidth
B. React Native does not support the 'border' shorthand property
C. Margin value must be a string, not a number
D. Margin cannot be set without padding

Solution

  1. Step 1: Check margin syntax

    Margin: 15 is valid as a number for all sides.
  2. Step 2: Check border property

    React Native does not support CSS shorthand like 'border: 2px solid black'. It requires separate properties: borderWidth and borderColor.
  3. Final Answer:

    React Native does not support the 'border' shorthand property -> Option B
  4. Quick Check:

    No 'border' shorthand in React Native [OK]
Hint: Use borderWidth and borderColor separately, no shorthand [OK]
Common Mistakes:
  • Using CSS shorthand border property
  • Thinking margin needs to be string
  • Believing margin requires padding
5. You want a View with a 15 pixel red border, 10 pixels padding inside, and 20 pixels margin outside. Which style object achieves this correctly?
hard
A. { borderWidth: 15, borderColor: 'red', padding: 10, margin: 20 }
B. { borderWidth: 10, borderColor: 'red', padding: 20, margin: 15 }
C. { border: '15px solid red', padding: 10, margin: 20 }
D. { borderWidth: 15, borderColor: 'red', padding: 20, margin: 10 }

Solution

  1. Step 1: Match borderWidth and borderColor

    Border should be 15 pixels thick and red, so borderWidth: 15 and borderColor: 'red' are correct.
  2. Step 2: Match padding and margin values

    Padding inside should be 10, margin outside 20, so padding: 10 and margin: 20 are correct.
  3. Step 3: Check other options for errors

    { borderWidth: 10, borderColor: 'red', padding: 20, margin: 15 } swaps padding and margin values; { border: '15px solid red', padding: 10, margin: 20 } uses unsupported border shorthand; { borderWidth: 15, borderColor: 'red', padding: 20, margin: 10 } swaps padding and margin values.
  4. Final Answer:

    { borderWidth: 15, borderColor: 'red', padding: 10, margin: 20 } -> Option A
  5. Quick Check:

    Correct border, padding, margin values [OK]
Hint: Match each property to its exact value carefully [OK]
Common Mistakes:
  • Swapping padding and margin values
  • Using CSS border shorthand
  • Incorrect borderWidth or borderColor
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard