When creating user interfaces in OutSystems, aligning items horizontally across different devices can be tricky, especially when building responsive layouts. In today’s dev tip, expert OutSystems Developer Izam Basiron compares two common methods for creating columns in OutSystems: the traditional column width approach and the more modern column widget. He also shares practical tips for aligning items using Flexbox, a powerful tool that offers more control and flexibility for responsive designs.
Method 1: Traditional Column Width Approach
The column width method in OutSystems is a classic way to define layouts. It uses fixed fractional widths such as four-col or three-col to set column sizes.
Pros:
- Straightforward: Easy to implement for basic layouts.
- Fixed Layout: Provides a rigid structure, which can be useful for some projects.
Cons:
- Limited Responsiveness: It doesn’t adapt well to different screen sizes, especially on smaller devices like tablets or phones.
- Inconsistent Styling: Maintaining consistent styling across multiple screen sizes can be a challenge, making this method less versatile.
Method 2: Column Widget (Flexbox-Based)
The column widget, on the other hand, is based on Flexbox, a modern layout system that offers far greater control over how columns behave across different devices. Flexbox allows developers to fine-tune responsiveness, ensuring that layouts adjust smoothly depending on the screen size.
Pros:
- Fine-Grained Control: Offers flexibility over how columns adjust on different screen sizes.
- Responsive: Adapts to various devices more seamlessly, providing better control over user experience.
Cons:
- Slight Learning Curve: Flexbox can be more complex for developers who are unfamiliar with its properties.
Column Width vs. Column Widget: Side-by-Side Comparison
On Tablets
- Column Width: The layout stays the same as on a larger screen but with reduced margins, which can make the content feel cramped.
- Column Widget: Adapts based on the responsive settings you apply, allowing for more flexibility and a better fit on tablets.
On Phones
- Column Width: Often collapses into a single column, which may not be ideal for all use cases.
- Column Widget: With Flexbox, you have the power to control how columns break on smaller screens. You can decide which columns collapse first and in what order, ensuring the layout remains user-friendly.
Practical Tips for Aligning Items Using Flexbox
Flexbox is a versatile and reliable layout system that can help you create clean, professional UIs in OutSystems. Here are a few practical tips for aligning items horizontally using Flexbox properties:
1. Title with Icon
To align a title with an icon, use display: flex. Apply align-items: baseline to ensure that the text and icon are aligned along the baseline of the text. Additionally, use justify-content: space-between to push the items to opposite ends of the container. This is perfect for creating a balanced layout with titles and icons.