Test your understanding of CSS Flexbox and Grid Layout with this easy-level quiz. Assess your knowledge of core properties, layout techniques, and key differences essential for building responsive web designs using modern CSS layout systems.
Which CSS property do you use to turn a container into a flex formatting context for its children?
Explanation: The 'display: flex;' property enables flexbox layout on a container, allowing its direct children to become flex items. 'position: flex;' is not a valid CSS property, and 'flex-direction: block;' is incorrect as flex-direction only sets the direction, not the display context. 'flex-container: on;' is not a recognized CSS property.
If you set 'flex-direction: row-reverse;' on a flex container, in which direction will the main axis flow?
Explanation: 'flex-direction: row-reverse;' reverses the default row flow, making the main axis go from right to left. 'Left to right' is the default for 'row'. Flexbox only uses 'top to bottom' and 'bottom to top' for column directions, not row directions.
Which property is used to define the number and size of columns in a grid container?
Explanation: 'grid-template-columns' specifies the column track sizes and number in a grid container, allowing explicit control over the grid structure. 'flex-columns', 'columns-set', and 'layout-cols' are not valid CSS grid properties and would not produce any effect.
To horizontally center a single flex item inside a flex container, which property should be set on the container?
Explanation: 'justify-content: center;' horizontally centers items along the main axis (default is horizontal in row direction) in a flex container. 'align-items: start;' aligns items to the start of the cross axis, not the center. 'float: center;' and 'item-center: horizontal;' are invalid CSS properties.
When should you prefer Grid layout over Flexbox?
Explanation: Grid is intended for two-dimensional layouts, allowing you to control both rows and columns. Flexbox is mainly for one-directional layouts (row or column). Float-based layouts are unrelated to Grid, and while both flexbox and grid can be used with block or inline elements, that is not a distinguishing factor.
If you use 'display: flex;' on a container and do not specify 'flex-direction', what is the default direction?
Explanation: The default 'flex-direction' when not specified is 'row', meaning items are laid out from left to right. 'Column (top to bottom)' would require setting 'flex-direction: column;'. 'Row (right to left)' requires 'row-reverse', and 'grid' is not a value for flex-direction.
Which property allows a grid item to span multiple columns in a grid layout?
Explanation: 'grid-column' defines the start and end line for a grid item, controlling how many columns it spans. 'flex-grow' applies to flexbox and does not influence grid item spanning. 'column-span' and 'spanning-columns' are not standard properties for grid item placement.
What does 'gap: 20px;' do when applied to a flex container?
Explanation: The 'gap' property (previously called 'grid-gap') adds consistent spacing between flex items. Setting each item's width requires a different property. It does not affect borders or merge items together; its only purpose is controlling the space between items.
To vertically center all items within each grid cell, which property could you use on the grid container?
Explanation: 'align-items: center;' centers content vertically within each grid area or cell. 'justify-items: start;' would align content to the start horizontally. 'vertical-align: middle;' only applies to inline elements, and 'center-items: vertical;' is not a valid CSS property.
What does the property 'flex-grow: 2;' do for a flex item among its siblings?
Explanation: 'flex-grow: 2;' lets the flex item take up twice the available space relative to items with 'flex-grow: 1'. It does not affect order, size by pixels, or font size. The other options misunderstand the 'flex-grow' property's function in distributing extra space.