RevealTheme logo

Bộ tạo Flexbox CSS

Tạo các bố cục CSS bằng flexbox một cách trực quan. Xem kết quả theo thời gian thực trong khi bạn điều chỉnh hướng, căn chỉnh, ngắt dòng và khoảng cách.

1
2
3
4
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: stretch;
flex-wrap: nowrap;
gap: 8px;

Cách sử dụng công cụ này

  1. 1

    Pick values from the four dropdowns: flex-direction, justify-content, align-items, and flex-wrap.

  2. 2

    Drag the gap slider to set the spacing between items, from 0 to 40 pixels.

  3. 3

    Watch the live preview of four numbered boxes update instantly to reflect each change.

  4. 4

    Click 'Copy CSS' to copy the generated declaration block, then paste it onto your own flex container.

Bộ tạo Flexbox CSS là gì?

Flexbox là cách hiện đại để sắp xếp các phần tử trong CSS, đơn giản hơn nhiều so với float hay định vị tuyệt đối. Các thuộc tính gồm: flex-direction (hàng hoặc cột), justify-content (căn chỉnh trên trục chính), align-items (trục ngang), flex-wrap và gap. Công cụ này phơi bày tất cả chúng kèm theo bản xem trước theo thời gian thực.

Các trường hợp sử dụng phổ biến

  • Aligning a horizontal navigation bar so links sit at flex-start and a logo or button pushes to flex-end with space-between.

  • Centering a single element both horizontally and vertically using justify-content: center and align-items: center.

  • Spacing a row of buttons or tags evenly with a fixed gap instead of fragile margins.

  • Stacking form fields vertically by switching flex-direction to column while keeping consistent gap spacing.

  • Letting a row of cards wrap onto new lines on narrow screens with flex-wrap: wrap.

  • Learning how justify-content and align-items behave by toggling values and watching the live preview before committing the code.

Câu hỏi thường gặp

Flexbox hay Grid?
Hãy dùng flexbox cho các bố cục một chiều (một hàng nút, một thanh điều hướng). Hãy dùng CSS Grid cho các bố cục hai chiều (các thẻ trong một lưới đáp ứng).

Công cụ liên quan