Overview
AContainer is a widget that aligns its contents within its boundaries and can apply visual styling like backgrounds, borders, and shadows. It’s one of the fundamental layout widgets in Iced.
Constructor
container::Container::new
Container with the given content.
Parameters:
content- The widget to place inside the container
Builder Methods
Identity
id
Layout
width
height
max_width
max_height
padding
Alignment
center
center_x
center_y
align_x
Left, Center, or Right.
align_y
Top, Center, or Bottom.
align_left / align_right / align_top / align_bottom
Appearance
clip
style
Style
Style Builders
Built-in Styles
transparent- No background or borderbackground(color)- Simple colored backgroundrounded_box- Rounded corners with backgroundbordered_box- Border with backgroundprimary- Primary color backgroundsecondary- Secondary color backgroundsuccess- Success/positive color (green)warning- Warning color (yellow/orange)danger- Danger/error color (red)dark- Dark background with white text
Examples
Basic Container
Centered Content
With Background
Using Built-in Styles
Custom Alignment
Card-like Container
Clipping Overflow
Status Badge
Responsive Centering
Gradient Background
Sidebar Container
Use Cases
- Layout control: Centering or aligning content
- Visual grouping: Adding backgrounds and borders to group related widgets
- Spacing: Adding padding around content
- Responsive design: Using with
Length::Filland max dimensions - Cards and panels: Creating distinct visual sections
- Clipping: Preventing content overflow
Related
Scrollable
For scrollable content
Layout Guide
Learn more about layout
