PrimeFlex provides various spacing utilities to modify an element's layout.
The spacing classes use the p-{property}{position}-{value} syntax whereas for responsive values p-{property}{position}-{breakpoint}-{value} format is used.
Property can either be a margin or a padding.
Position are available for the individual sides, the x-y axis or blank for the shortand of all sides.
Value field varies from 0 to 6 where default value of the $spacer is 1rem. The special auto value is available to margins only and used to center elements.
Breakpoints define how the spacing should be defined depending on the screen size. Design is mobile first so smaller values can also apply to larger values e.g. md also applies to lg or xl if they are not explicitly defined.
<div class="p-mb-2">Margin bottom with level 2</div>
<div class="p-mt-4">Margin top with level 2</div>
<div class="p-m-2">Margin for all sides with level 2</div>
<div class="p-mx-auto">Auto margins for left and right side</div>
<div class="p-pb-4">Padding bottom with level 4</div>
<div class="p-p-1">Padding for all sides with level 1</div>
<div class="p-m-1 p-p-1 p-m-lg-3 p-b-lg-3">Level 3 spacing for lg screens and level 1 for smaller screens (xs).</div>
A custom build with different values can be obtained from PrimeFlex using the _variables.scss file.
<div class="card">
<h5>Margin</h5>
<h6>Without Spacing</h6>
<p:commandButton type="button" value="Button 1" style="width:20rem" />
<p:commandButton type="button" value="Button 2" style="width:20rem" />
<h6>With Spacing</h6>
<p:commandButton type="button" value="Button 1" style="width:20rem" styleClass="p-mr-2 p-mb-2" />
<p:commandButton type="button" value="Button 2" style="width:20rem" styleClass="p-mb-2"/>
<h5>Responsive Margin</h5>
<h6>Without Spacing</h6>
<div class="p-grid p-formgrid ui-fluid">
<div class="p-col-12 p-lg-4">
<p:inputText />
</div>
<div class="p-col-12 p-lg-4">
<p:inputText />
</div>
<div class="p-col-12 p-lg-4">
<p:inputText />
</div>
</div>
<h6>With Spacing</h6>
<div class="p-grid p-formgrid ui-fluid">
<div class="p-col-12 p-mb-2 p-lg-4 p-mb-lg-0">
<p:inputText />
</div>
<div class="p-col-12 p-mb-2 p-lg-4 p-mb-lg-0">
<p:inputText />
</div>
<div class="p-col-12 p-mb-2 p-lg-4 p-mb-lg-0">
<p:inputText />
</div>
</div>
<h6>Center</h6>
<div class="demo-container p-p-4">
<p:commandButton type="button" value="Button" styleClass="p-d-block p-mx-auto" />
</div>
</div>
<div class="card">
<h5>Padding</h5>
<h6>Without Spacing</h6>
<div class="demo-container">
<p:commandButton type="button" value="Button" />
</div>
<h6>With Spacing</h6>
<div class="demo-container p-p-3">
<p:commandButton type="button" value="Button" />
</div>
<h6>Responsive Spacing</h6>
<div class="demo-container p-p-0 p-p-sm-1 p-p-md-2 p-p-lg-3">
<p:commandButton type="button" value="Button" />
</div>
</div>