What is primeflex?
PrimeFlex is a lightweight, responsive CSS utility library that provides a variety of classes to help with layout, spacing, alignment, and more. It is designed to be used with PrimeReact, but it can be used independently as well.
What are primeflex's main functionalities?
Grid System
PrimeFlex provides a responsive grid system that allows you to create complex layouts with ease. The grid system is based on a 12-column layout, and you can specify the number of columns each element should span.
<div class="p-grid">
<div class="p-col-6">Column 1</div>
<div class="p-col-6">Column 2</div>
</div>
Flexbox Utilities
PrimeFlex includes a variety of flexbox utilities to help with alignment and spacing. These utilities make it easy to center content, align items, and distribute space within a container.
<div class="p-d-flex p-jc-center p-ai-center">
<div>Centered Content</div>
</div>
Spacing Utilities
PrimeFlex provides a set of spacing utilities to control margin and padding. These utilities allow you to quickly add or remove space around elements without writing custom CSS.
<div class="p-m-4 p-p-4">
<div>Content with margin and padding</div>
</div>
Responsive Design
PrimeFlex includes responsive design utilities that allow you to create layouts that adapt to different screen sizes. You can specify different column spans for different breakpoints, making it easy to create responsive designs.
<div class="p-grid">
<div class="p-col-12 p-md-6 p-lg-4">Responsive Column</div>
</div>
Other packages similar to primeflex
bootstrap
Bootstrap is a popular CSS framework that provides a comprehensive set of tools for building responsive, mobile-first websites. It includes a grid system, pre-designed components, and a variety of utilities for spacing, alignment, and more. Compared to PrimeFlex, Bootstrap is more feature-rich and includes a wider range of pre-designed components.
tailwindcss
Tailwind CSS is a utility-first CSS framework that provides a large set of utility classes for building custom designs without writing custom CSS. It offers a high level of customization and flexibility, making it a popular choice for developers who want to create unique designs. Compared to PrimeFlex, Tailwind CSS offers more customization options and a larger set of utilities.
bulma
Bulma is a modern CSS framework based on Flexbox. It provides a simple and clean syntax for creating responsive layouts and includes a variety of components and utilities for building web interfaces. Compared to PrimeFlex, Bulma is more focused on providing a clean and easy-to-use syntax for building responsive layouts.
PrimeFlex
PrimeFlex is a lightweight flex based responsive layout utility optimized for mobile phones, tablets and desktops.
Getting Started
FlexGrid is a CSS utility based on flexbox. For more information about Flex, visit A Complete Guide to Flexbox. A basic grid is defined by giving a container p-grid class and children the p-col class. Children of the grid will have the same width and scale according to the width of the parent.
<div class="p-grid">
<div class="p-col">1</div>
<div class="p-col">2</div>
<div class="p-col">3</div>
</div>
Direction
Default direction is "row" and p-dir-* class at the container defines the other possible directions which can be "row reverse", "column" and "column reverse".
<div class="p-grid p-dir-rev">
<div class="p-col">1</div>
<div class="p-col">2</div>
<div class="p-col">3</div>
</div>
<div class="p-grid p-dir-col">
<div class="p-col">1</div>
<div class="p-col">2</div>
<div class="p-col">3</div>
</div>
<div class="p-grid p-dir-col-rev">
<div class="p-col">1</div>
<div class="p-col">2</div>
<div class="p-col">3</div>
</div>
12 Column Grid
FlexGrid includes a 12 column based layout utility where width of a column is defined with the p-col-{number} style class. Columns with prefined widths can be used with columns with auto width (p-col) as well.
In the first example below, first column covers the 4 units out of 12 and the rest of the columns share the remaining space whereas in the second example, all three columns have explicit units.
<div class="p-grid">
<div class="p-col-4">4</div>
<div class="p-col">1 </div>
<div class="p-col">1 </div>
<div class="p-col">1 </div>
<div class="p-col">1 </div>
<div class="p-col">1 </div>
<div class="p-col">1 </div>
<div class="p-col">1 </div>
<div class="p-col">1 </div>
</div>
<div class="p-grid">
<div class="p-col-2">2</div>
<div class="p-col-6">6</div>
<div class="p-col-4">4</div>
</div>
Multi Line
When the number of columns exceed 12, columns wrap to a new line.
<div class="p-grid">
<div class="p-col-6">6</div>
<div class="p-col-6">6</div>
<div class="p-col-6">6</div>
<div class="p-col-6">6</div>
</div>
Fixed Width Column
A column can have a fixed width while siblings having auto width. Apply p-col-fixed class to fix a column width.
<div class="p-grid">
<div class="p-col-fixed" style="width:100px">Fixed</div>
<div class="p-col">Auto</div>
</div>
Responsive
Responsive layout is achieved by applying breakpoint specific classes to the columns whereas p-col-* define the default behavior for mobile devices with small screens. Four screen sizes are supported with different breakpoints.
- p-sm-* : min-width 576px
- p-md-* : min-width 768px
- p-lg-* : min-width 992px
- p-xl-* : min-width 1200px
In example below, large screens display 4 columns, medium screens display 2 columns in 2 rows and finally on small devices, columns are stacked.
<div class="p-grid">
<div class="p-col-12 p-md-6 p-lg-3">A</div>
<div class="p-col-12 p-md-6 p-lg-3">B</div>
<div class="p-col-12 p-md-6 p-lg-3">C</div>
<div class="p-col-12 p-md-6 p-lg-3">D</div>
</div>
Horizontal Alignment
p-justify-* classes are used on the container element to define the alignment along the main axis.
- p-justify-start: (default) Items are packed toward the start line
- p-justify-end : Items are re packed toward to end line
- p-justify-center : Items are centered along the line
- p-justify-between: Items are evenly distributed in the line; first item is on the start line, last item on the end line
- p-justify-around: Items are evenly distributed in the line with equal space around them.
- p-justify-even: Items are distributed so that the spacing between any two items (and the space to the edges) is equal.
<div class="p-grid p-justify-between">
<div class="p-col-2">2</div>
<div class="p-col-1">1</div>
<div class="p-col-4">4</div>
</div>
Vertical Alignment
*p-align-* classes are used on the container element to define the alignment along the cross axis.
- p-align-stretch: (default) Stretch to fill the container.
- p-align-start : Cross-start margin edge of the items is placed on the cross-start line
- p-align-end : Cross-end margin edge of the items is placed on the cross-end line
- p-align-center : Items are centered in the cross-axis
- p-align-baseline : Items are aligned such as their baselines align
<div class="p-grid p-align-center">
<div class="p-col">4</div>
<div class="p-col">4</div>
<div class="p-col">4</div>
</div>
Vertical alignment can also be defined at column level with the p-col-align-* classes
- p-col-align-stretch : (default) Stretch to fill the container.
- p-col-align-start : Cross-start margin edge of the items is placed on the cross-start line
- p-col-align-end : Cross-end margin edge of the items is placed on the cross-end line
- p-col-align-center : Items are centered in the cross-axis
- p-col-align-baseline : Items are aligned such as their baselines align
<div class="p-grid">
<div class="p-col p-col-align-start">
<div class="box">4</div>
</div>
<div class="p-col p-col-align-center">
<div class="box">4</div>
</div>
<div class="p-col p-col-align-end">
<div class="box">4</div>
</div>
</div>
Offset
Offset classes allow defining a left margin on a column to avoid adding empty columns for spacing.
<div class="p-grid">
<div class="p-col-6 p-offset-3">6</div>
</div>
<div class="p-grid">
<div class="p-col-4">4 </div>
<div class="p-col-4 p-offset-4">4</div>
</div>
The list of offset classes varying within a range of 1 to 12.
- p-col-offset-* : All screens
- p-sm-offset-* : min-width: 576px
- p-md-offset-* : min-width: 768px
- p-lg-offset-* : min-width: 992px
- p-xl-offset-* : min-width: 1200px
Nested
Columns can be nested to create more complex layouts.
<div class="p-grid">
<div class="p-col-8">
<div class="p-grid">
<div class="p-col-6">
6
</div>
<div class="p-col-6">
6
</div>
<div class="p-col-12">
12
</div>
</div>
</div>
<div class="p-col-4">
4
</div>
</div>
Gutter
A .5 em padding is applied to each column along with negative margins on the container element, in case you'd like to remove these gutters, apply .p-nogutter class to the container. Note that this will not only remove the negative margins of the container, but also the padding of the columns.
<div class="p-grid p-nogutter">
<div class="p-col">1</div>
<div class="p-col">2</div>
<div class="p-col">3</div>
</div>
Gutters can also be removed from individual columns with the .p-col-nogutter class.
<div class="p-grid">
<div class="p-col">1</div>
<div class="p-col p-col-nogutter">2</div>
<div class="p-col">3</div>
</div>