Building responsive sites with Zurb Foundation for Sites is a game-changer for web developers. It's a powerful tool that helps you create sites that adapt to any screen size or device.
Foundation for Sites is a modular framework that provides a solid foundation for building responsive sites. It includes a robust grid system that allows you to create layouts that are easily adaptable to different screen sizes.
One of the key benefits of using Foundation for Sites is that it's highly customizable. You can easily swap out components and modify the code to fit your specific needs.
With Foundation for Sites, you can create responsive sites that look great on any device, from smartphones to desktops.
Download and Install
You can download a default or custom CSS package from the download page to get started with Foundation. This is the simplest way to get going.
If you're using the Sass version of Foundation, you can import foundation-flex.css in place of foundation.css, or set $xy-grid to false in Sass. This will enable a framework-wide flexbox mode.
You can download Foundation CSS from the download page, or use a package manager to install it. To use a package manager, click on Package Manager Installation, then scroll down to "install with Package Managers."
To install Foundation using the CLI, click here and scroll to "Install with Foundation via CLI." This will guide you through the installation process.
You can also install Foundation using CDN. To do this, visit https://get.foundation/, click on CDN to copy the link, and paste it into your IDE using the code below.
Here's a quick rundown of the installation options:
- Download the source files manually from the download page.
- Use a package manager, such as npm or yarn, to install Foundation.
- Install Foundation using the CLI.
- Use CDN to install Foundation.
Foundation Basics
The structure of the flex grid in Zurb Foundation is identical to that of the float grid.
Rows in Foundation use the class .row, and columns use the class .column (or .columns).
Basic percentage-based sizing can be done using the same grid classes you're used to: .small-6, .medium-12, and so on.
Foundation's grid classes allow for easy and flexible layout design.
To get started with building a responsive site using Foundation, you'll need to install it first.
The official documentation for Foundation is divided into separate sections for the site and email templates.
Layout and Sizing
A well-designed layout is crucial for any website, and Zurb Foundation makes it easy to achieve with its flexible grid system. You can add a sizing class to a column to control its behavior, and if you don't add one, it will simply expand to fill the leftover space.
Multiple expanding columns will share the leftover space equally, which can be useful for creating a responsive design. You can also make a column shrink by adding the .shrink class, which means it will only take up the horizontal space its contents need.
The grid system also allows you to create a block grid for a flex grid row using the flex-grid-layout mixin. This mixin takes two parameters: $n, which specifies the number of columns to display on each row, and $selector, which is a selector to use to target columns within the row.
If you want to stack all columns in a row by default and then unstack them on a larger screen size, you can use the .[size]-unstack classes. This shorthand class will stack the columns on smaller screen sizes and make each one equal-width on larger screens.
Here's a summary of the default grid styles modifications:
Advanced Sizing
Advanced Sizing is a crucial aspect of layout design, and it's great to have some control over how your columns behave.
If no sizing class is added to the column, it will simply expand to fill the leftover space. This is called an expand behavior.
Multiple expanding columns will share the leftover space equally, making it easy to create responsive layouts.
A column can also be made to shrink by adding the .shrink class, which means it will only take up the horizontal space its contents need. This is useful for creating layouts with varying content lengths.
You can mix and match expand and shrink behaviors to create complex layouts that adapt to different content types.
Here's a quick rundown of the different sizing behaviors:
By understanding these sizing behaviors, you can create layouts that are both functional and visually appealing.
Automatic Stacking
Automatic stacking is a convenient feature that allows you to stack all columns in a row by default.
You can use the .[size]-unstack classes to achieve this behavior. This shorthand class is a time-saver, making it easy to create responsive layouts.
By default, all columns will be stacked, taking up the full width of the row. This is great for small screens or mobile devices.
On a larger screen size, the columns will automatically unstack and become equal-width. This is a nice touch, as it ensures a clean and organized layout without requiring manual adjustments.
Vertical Alignment
Vertical alignment is a crucial aspect of designing a website's layout. By default, all columns in a flex grid stretch to be equal height.
You can change this behavior with alignment classes, which allow for middle alignment in CSS. Your options for vertical alignment are top, middle, bottom, and stretch.
Applying a vertical alignment class to the flex row will affect every column directly inside it. This means you can easily adjust the alignment of multiple columns at once.
Individual columns can also be aligned using the .align-self-* classes, which replace the old method of using .align-* classes on columns. This new approach was introduced in Foundation 6.2 and has been the standard since Foundation 6.3.
Collapse/Uncollapse Rows
The .collapse class is a game-changer for removing column gutters, or padding, in your layout.
You can use this class to remove gutters at specific media query sizes, which is super useful for creating custom layouts.
There are times when you won't want each media query to be collapsed or uncollapsed, so you can use the media query size you want and add the .collapse class to your row element.
For example, you can have gutters at small and medium sizes, but no gutters on large and up. This is a great way to create a layout that adapts to different screen sizes.
The .is-collapse-child class is also handy for removing negative margins from nested rows under collapsed parents, which can be a real pain to deal with otherwise.
Responsive Adjustments
To make columns stack on smaller screens, you'll need to add the class .small-12 manually. This is what allows them to shrink and stack properly.
Columns in a flex grid won't wrap if they're not given an explicit size. This is what makes auto-sizing work its magic.
To switch back to the expand behavior, use the classes .medium-expand or .large-expand. This will make your columns become even-width on larger screens.
Adding .small-12 is a simple way to make your columns stack on smaller screens, and it's a great solution for responsive design.
Grid Systems
Grid Systems are a crucial part of any website, allowing you to arrange content in a clear and organized manner.
To define column widths at the row-level, you can use the class .[size]-up-[n] on a row, where [n] is the number of columns to display per row, and [size] is the breakpoint at which to apply the effect.
A block grid row has the property align-items: stretch by default, which means the columns in each row are equal height. You can change this by modifying the align-items property of the row or using one of the vertical alignment flexbox classes.
If you need more control over your grid rows, you can use the flex-grid-row mixin. This mixin allows you to set various parameters, including the maximum size of the row, the number of columns, and whether to use nesting or collapsing behavior.
Here are the parameters you can use with the flex-grid-row mixin:
The flex-grid-layout mixin is another useful tool for creating block grids. It allows you to specify the number of columns to display on each row and the selector to use to target columns within the row.
Frequently Asked Questions
Is Zurb Foundation free?
Yes, Zurb Foundation is free, as it originated from the company's own style guide and was created to facilitate rapid prototyping. This open-source foundation has been a valuable resource for developers and designers ever since.
What is Zurb Foundation?
Zurb Foundation is a popular front-end framework that simplifies web development with pre-built HTML, CSS, and JavaScript components. It's known for its ease of use and flexibility, making it a great choice for building responsive and modern web applications.
What is the most advanced responsive front-end framework in the world?
Foundation is the most advanced responsive front-end framework globally, enabling seamless device compatibility. It accelerates development from prototype to production, perfect for building responsive sites and apps.
Featured Images: pexels.com