Styling & Flexbox Questions with Answers

14 practice questions on Styling & Flexbox (React Native) with answers and step-by-step solutions. Try 10 samples below, then practise all 14 free in the AptiNest app.

Sample questions

Question 1Easy

Which of these is a valid width value in a React Native style?

  1. '50px'
  2. '50vw'
  3. '50%'
  4. '50rem'

Answer: C. '50%'

Explanation

React Native accepts plain numbers (dp) or percentage strings. CSS units such as px, vw and rem are not supported.

Step-by-step solution

  1. React Native accepts plain numbers and percentage strings for width.
  2. A percentage string such as '50%' is valid.
  3. So the valid width value is '50%', which is option C.

Why the other options are wrong

  • A. Px units are not supported; use a plain number instead.
  • B. Vw units are not supported in React Native.
  • D. Rem units are not supported in React Native.

Tip: Use numbers for fixed sizes and percentage strings for relative sizes.

Question 2Easy

In a style such as { width: 100 }, what unit is the number in?

  1. Density-independent pixels (unitless)
  2. Physical screen pixels on the device
  3. Percent of the parent's width
  4. Points that are always equal to CSS rem

Answer: A. Density-independent pixels (unitless)

Explanation

React Native dimensions are unitless and density-independent, so 100 looks about the same size on low- and high-density screens.

Step-by-step solution

  1. Numbers in a React Native style are density-independent pixels, with no unit name.
  2. They scale with screen density, so 100 looks about the same size on different screens.
  3. So the number is unitless and density-independent, which is option A.

Why the other options are wrong

  • B. Physical pixels are not used; a number is scaled by density.
  • C. A percent needs a string such as '50%', not a plain number.
  • D. React Native has no rem unit.

Tip: Use plain numbers for sizes and strings like '50%' for percentages.

Question 3Easy

Does React Native support CSS class selectors or a global stylesheet cascade?

  1. No; each component gets its own style objects
  2. Yes, through className props on every core component
  3. Yes, but only for selectors written in a global.css file
  4. Yes, with full CSS specificity rules like browsers

Answer: A. No; each component gets its own style objects

Explanation

There are no selectors or cascade. Styles are applied directly to components, and sharing is done by reusing JS objects.

Step-by-step solution

  1. React Native has no CSS selectors, classes or global stylesheet cascade.
  2. Styles are given directly to each component as objects.
  3. Sharing is done by reusing the same JavaScript objects, so the answer is option A.

Why the other options are wrong

  • B. There is no className prop on core components.
  • C. There is no global.css file support in React Native.
  • D. React Native does not use CSS specificity rules.

Tip: Share styles by reusing StyleSheet objects or plain JavaScript objects.

Question 4Easy

What is the default flexDirection of a View in React Native?

  1. column
  2. row
  3. row-reverse
  4. none

Answer: A. column

Explanation

React Native defaults to column because phone screens are usually laid out top to bottom. The web default is row.

Step-by-step solution

  1. React Native's default flexDirection is column.

Why the other options are wrong

  • B. Row is the web default.
  • C. Not the default.
  • D. none isn't valid.

Tip: RN column, web row.

Question 5Medium

Which flexbox default in React Native differs from the CSS default on the web?

  1. flexShrink is 0 rather than 1
  2. justifyContent is center rather than flex-start
  3. alignItems is center rather than stretch
  4. flexWrap is wrap rather than nowrap

Answer: A. flexShrink is 0 rather than 1

Explanation

React Native items do not shrink by default (flexShrink 0), whereas on the web they do. flexDirection column and alignContent flex-start are the other well-known differences.

Step-by-step solution

  1. In React Native, flexShrink defaults to 0, so items do not shrink.
  2. On the web, flex items shrink by default with flex-shrink 1.
  3. So the difference is flexShrink, which is option A.

Why the other options are wrong

  • B. JustifyContent defaults to flex-start in React Native, the same as the web.
  • C. AlignItems defaults to stretch in React Native, the same as the web.
  • D. FlexWrap defaults to nowrap in React Native, the same as the web.

Tip: Set flexShrink: 1 on React Native children that must shrink to fit.

Question 6Medium

In a column container with default alignment, a child View has no width set. How wide is it?

  1. Zero, so it is invisible until a width is given
  2. Full container width, since alignItems defaults to stretch
  3. As wide as its own content, like an inline element in HTML
  4. Half the container width, as the default flexBasis

Answer: B. Full container width, since alignItems defaults to stretch

Explanation

alignItems defaults to stretch, so children of a column stretch across the cross axis (the width).

Step-by-step solution

  1. AlignItems defaults to stretch in React Native.
  2. In a column container, the cross axis is the width, so children stretch across it.
  3. So the child View takes the full container width, which is option B.

Why the other options are wrong

  • A. The child is not zero width; stretch gives it the full width.
  • C. It does not behave like an inline element, because flex layout stretches it.
  • D. FlexBasis does not set half the width in a column; stretch sets the width.

Tip: In a column layout, alignItems stretch makes children as wide as the container.

Question 7Medium

What does StyleSheet.absoluteFill provide?

  1. A style that fills the screen with a solid background
  2. position absolute plus top, right, bottom and left of 0
  3. A helper that turns all child styles into absolute ones
  4. A style setting width and height to the screen's pixels

Answer: B. position absolute plus top, right, bottom and left of 0

Explanation

absoluteFill is a ready-made style that makes a view overlay its parent exactly, handy for backgrounds and overlays.

Step-by-step solution

  1. absoluteFill is position absolute with all edges 0.
  2. So a view covers its parent.

Why the other options are wrong

  • A. No background colour.
  • C. It doesn't change children.
  • D. It does not use screen pixels.

Tip: absoluteFill = cover parent.

Question 8Medium

What is the result of style={[{ color: 'red', fontSize: 12 }, { color: 'blue' }]} on a Text?

  1. Blue text at font size 12
  2. Red text at font size 12
  3. Blue text at the default font size
  4. An error, since style must be a single object

Answer: A. Blue text at font size 12

Explanation

Style arrays are merged left to right, so later entries override earlier ones key by key. fontSize from the first object survives.

Step-by-step solution

  1. Style arrays are merged from left to right.
  2. The first object sets color red and fontSize 12; the second sets color blue.
  3. The later color overrides the earlier one, and fontSize 12 is kept.
  4. So the text is blue at font size 12, which is option A.

Why the other options are wrong

  • B. The later color blue overrides the earlier red.
  • C. FontSize 12 from the first object is kept, so it is not the default size.
  • D. Style arrays are allowed in React Native, so no error happens.

Tip: In a style array the last value for each key wins; other keys from earlier entries stay.

Question 9Hard

A child with position: 'absolute' and top: 0 is placed relative to what?

  1. The screen, like position: fixed in CSS
  2. The nearest ancestor view that sets a position explicitly
  3. Its parent, since every view is relative by default
  4. The root view of the current navigation screen

Answer: C. Its parent, since every view is relative by default

Explanation

In React Native the default position is relative, so the parent is always a positioned element and absolute children are laid out against it.

Step-by-step solution

  1. Every View in React Native is position relative by default.
  2. An absolute child is placed relative to its direct parent view.
  3. So the answer is option C, the parent.

Why the other options are wrong

  • A. It is not relative to the screen; the parent is used, unlike position fixed.
  • B. The nearest ancestor that sets a position explicitly is not the rule; the parent is always positioned.
  • D. The root view of a navigation screen is not the reference for absolute children.

Tip: An absolute child in React Native is placed against its parent, so give the parent a size and position.

Question 10Hard

A child View has flex: 1, but nothing appears. Its parent View has no flex and no height. What is the likely cause?

  1. flex: 1 is ignored unless the parent's flexDirection is set to row
  2. The parent collapses to its content, leaving no free space
  3. flex only works on direct children of the root View
  4. Views with flex need a backgroundColor before they draw

Answer: B. The parent collapses to its content, leaving no free space

Explanation

flex: 1 fills the free space of the parent. If the parent has no size of its own (no flex or height), it collapses to its content and the child gets zero height.

Step-by-step solution

  1. Flex: 1 fills the free space that the parent has.
  2. The parent has no flex and no height, so it has no size of its own.
  3. Without size, the parent shrinks to its content, leaving no free space, so the child gets zero height.
  4. So the likely cause is option B.

Why the other options are wrong

  • A. Flex works in column layouts too; flexDirection does not decide this.
  • C. Flex works on any child of a View, not only direct children of the root.
  • D. BackgroundColor does not affect whether a view gets space.

Tip: Give a parent flex: 1 or a height so that flex children have space to fill.

Practise all 14 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all React Native topics · All topics