Nudge an element towards the center
nudge
moves the element towards the center of its container with the margin
property.
<div class="card"> <div class="nudge [--nudge:0.5rem]"> Nudged element </div></div><!-- ... other positions ... -->
Combine nudge with other positioning utilities
nudge
is incredible when you combine it with pos
or fixed
.
Imagine you want an element to be positioned on the top right corner, and perhaps nudged a little bit to the center — you can do that with nudge
without diving into the nitty gritty CSS details.
<div class="stack"> <div class="pos-topright nudge-2"> Nudged element </div> <!-- ... other positions ... --></div>
Perfect inner border radius calulation
While nudging, you can enable automatic inner radius calculation to calculate the perfect border radius, every time!
Make interesting cards with nudge
Have you seen cards with backgrounds contained in a slight nudge? Well, you can do that easily too with nudge
and the inner border radius option!
Intro
nudge
lets you move elements towards the center by creating margin
around it. By itself, it’s nothing different from using margin
directly.
<div class="nudge [--nudge:1rem]"> ... </div>
<div class="m m-4"> ... </div>
Nudge Functional Utilities
We’ve built in functional utilities for nudge
so you can use nudge
like m
and p
with Tailwind.
<div class="nudge nudge-4"> ... </div>
<div class="m m-4"> ... </div>
Inner Radius Calculation
One main feature of nudge
is the ability to calculate inner radius of an element. To enable this feature, you need to set a --radius
variable to the enclosing element, and inner-radius
to the nudged element.
<div class="[--radius:1rem]"> <div class="nudge [--nudge:0.5rem] inner-radius"> ... </div></div>
Using Nudge with Pos and Fixed
nudge
is built into pos
and fixed
so you can just set the --nudge
variable without declaring the nudge
class.
<div class="stack"> <div class="pos-topleft [--nudge:0.5rem]"> ... </div></div>
<div class="stack"> <div class="fixed-topleft [--nudge:0.5rem]"> ... </div></div>
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.
Intro
nudge
lets you move elements towards the center by creating margin
around it. By itself, it’s nothing different from using margin
directly.
<div class="nudge [--nudge:1rem]"> ... </div>
<div class="m m-4"> ... </div>
Nudge Functional Utilities
We’ve built in functional utilities for nudge
so you can use nudge
like m
and p
with Tailwind.
<div class="nudge nudge-4"> ... </div>
<div class="m m-4"> ... </div>
Inner Radius Calculation
One main feature of nudge
is the ability to calculate inner radius of an element. To enable this feature, you need to set a --radius
variable to the enclosing element, and inner-radius
to the nudged element.
<div class="[--radius:1rem]"> <div class="nudge [--nudge:0.5rem] inner-radius"> ... </div></div>
Using Nudge with Pos and Fixed
nudge
is built into pos
and fixed
so you can just set the --nudge
variable without declaring the nudge
class.
<div class="stack"> <div class="pos-topleft [--nudge:0.5rem]"> ... </div></div>
<div class="stack"> <div class="fixed-topleft [--nudge:0.5rem]"> ... </div></div>
nudge
has the following CSS:
.nudge { margin-block: var(--nudge-y, var(--nudge, 0)); margin-inline: var(--nudge-x, var(--nudge, 0));}
.inner-radius { border-radius: calc(var(--radius) - var(--nudge));}
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.
nudge
has the following CSS:
.nudge { margin-block: var(--nudge-y, var(--nudge, 0)); margin-inline: var(--nudge-x, var(--nudge, 0));}
.inner-radius { border-radius: calc(var(--radius) - var(--nudge));}
Nudge
Modifiers
Class | Description |
---|---|
nudge | Nudge the element from all 4 directions |
nudge-top | Nudge the element from the top |
nudge-topright | Nudge the element from the top right corner |
nudge-bottomleft | Nudge the element from the bottom left corner |
nudge-bottom | Nudge the element from the bottom |
nudge-bottomright | Nudge the element from the bottom right corner |
nudge-left | Nudge the element from the left |
nudge-right | Nudge the element from the right |
inner-radius | Creates border radius based on --nudge and --radius |
Utilities
Class | Description |
---|---|
nudge-* | Amount of --nudge to apply |
nudge-x-* | Amount of --nudge-x to apply |
nudge-y-* | Amount of --nudge-y to apply |
CSS Variables
Variable | Default | Description |
---|---|---|
--nudge | 0 | Amount to to nudge on both block and inline axes |
--nudge-x | 0 | Amount to to nudge on the inline axis |
--nudge-y | 0 | Amount to to nudge on the block axis |
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.
Nudge
Modifiers
Class | Description |
---|---|
nudge | Nudge the element from all 4 directions |
nudge-top | Nudge the element from the top |
nudge-topright | Nudge the element from the top right corner |
nudge-bottomleft | Nudge the element from the bottom left corner |
nudge-bottom | Nudge the element from the bottom |
nudge-bottomright | Nudge the element from the bottom right corner |
nudge-left | Nudge the element from the left |
nudge-right | Nudge the element from the right |
inner-radius | Creates border radius based on --nudge and --radius |
Utilities
Class | Description |
---|---|
nudge-* | Amount of --nudge to apply |
nudge-x-* | Amount of --nudge-x to apply |
nudge-y-* | Amount of --nudge-y to apply |
CSS Variables
Variable | Default | Description |
---|---|---|
--nudge | 0 | Amount to to nudge on both block and inline axes |
--nudge-x | 0 | Amount to to nudge on the inline axis |
--nudge-y | 0 | Amount to to nudge on the block axis |