Back to Tailwindcss

Float

src/docs/float.mdx

latest8.4 KB
Original Source

import { ApiTable } from "@/components/api-table.tsx"; import { Example } from "@/components/example.tsx"; import { Figure } from "@/components/figure.tsx"; import { ResponsiveDesign } from "@/components/content.tsx";

export const title = "float"; export const description = "Utilities for controlling the wrapping of content around an element.";

<ApiTable rows={[ ["float-right", "float: right;"], ["float-left", "float: left;"], ["float-start", "float: inline-start;"], ["float-end", "float: inline-end;"], ["float-none", "float: none;"], ]} />

Examples

Floating elements to the right

Use the float-right utility to float an element to the right of its container:

<Figure> <Example resizable> { <>
  <p className="text-justify">
    Maybe we can live without libraries, people like you and me. Maybe. Sure, we're too old to change the world, but
    what about that kid, sitting down, opening a book, right now, in a branch at the local library and finding
    drawings of pee-pees and wee-wees on the Cat in the Hat and the Five Chinese Brothers? Doesn't HE deserve
    better? Look. If you think this is about overdue fines and missing books, you'd better think again. This is
    about that kid's right to read a book without getting his mind warped! Or: maybe that turns you on, Seinfeld;
    maybe that's how y'get your kicks. You and your good-time buddies.
  </p>
</>

} </Example>

html
<!-- [!code classes:float-right] -->
<article>
  
  <p>Maybe we can live without libraries, people like you and me. ...</p>
</article>
</Figure>

Floating elements to the left

Use the float-left utility to float an element to the left of its container:

<Figure> <Example resizable> { <>
  <p className="text-justify">
    Maybe we can live without libraries, people like you and me. Maybe. Sure, we're too old to change the world, but
    what about that kid, sitting down, opening a book, right now, in a branch at the local library and finding
    drawings of pee-pees and wee-wees on the Cat in the Hat and the Five Chinese Brothers? Doesn't HE deserve
    better? Look. If you think this is about overdue fines and missing books, you'd better think again. This is
    about that kid's right to read a book without getting his mind warped! Or: maybe that turns you on, Seinfeld;
    maybe that's how y'get your kicks. You and your good-time buddies.
  </p>
</>

} </Example>

html
<!-- [!code classes:float-left] -->
<article>
  
  <p>Maybe we can live without libraries, people like you and me. ...</p>
</article>
</Figure>

Using logical properties

Use the float-start and float-end utilities, which use logical properties to map to either the left or right side based on the text direction:

<Figure> <Example resizable> { <> <div dir="ltr"> <p className="mb-4 font-mono text-xs font-medium text-gray-500 dark:text-gray-400">left-to-right</p> <div>
      <p className="text-justify">
        Maybe we can live without libraries, people like you and me. Maybe. Sure, we're too old to change the world,
        but what about that kid, sitting down, opening a book, right now, in a branch at the local library and
        finding drawings of pee-pees and wee-wees on the Cat in the Hat and the Five Chinese Brothers? Doesn't HE
        deserve better? Look. If you think this is about overdue fines and missing books, you'd better think again.
        This is about that kid's right to read a book without getting his mind warped! Or: maybe that turns you on,
        Seinfeld; maybe that's how y'get your kicks. You and your good-time buddies.
      </p>
    </div>
  </div>
  <div dir="rtl" className="mt-6">
    <p className="mb-4 font-mono text-xs font-medium text-gray-500 dark:text-gray-400">right-to-left</p>
    <div>
      
      <p className="text-justify">
        ربما يمكننا العيش بدون مكتبات، أشخاص مثلي ومثلك. ربما. بالتأكيد، نحن أكبر من أن نغير العالم، ولكن ماذا عن
        ذلك الطفل الذي يجلس ويفتح كتابًا الآن في أحد فروع المكتبة المحلية ويجد رسومات للتبول والبول على القطة في
        القبعة والإخوة الصينيون الخمسة؟ ألا يستحق الأفضل؟ ينظر. إذا كنت تعتقد أن الأمر يتعلق بالغرامات المتأخرة
        والكتب المفقودة، فمن الأفضل أن تفكر مرة أخرى. يتعلق الأمر بحق ذلك الطفل في قراءة كتاب دون أن يتشوه عقله! أو:
        ربما يثيرك هذا يا سينفيلد؛ ربما هذه هي الطريقة التي تحصل بها على ركلاتك. أنت ورفاقك الطيبين.
      </p>
    </div>
  </div>
</>

} </Example>

html
<!-- [!code word:dir="rtl"] -->
<!-- [!code classes:float-start] -->
<article>
  
  <p>Maybe we can live without libraries, people like you and me. ...</p>
</article>

<article dir="rtl">
  
  <p>... ربما يمكننا العيش بدون مكتبات، أشخاص مثلي ومثلك. ربما. بالتأكيد</p>
</article>
</Figure>

Disabling a float

Use the float-none utility to reset any floats that are applied to an element:

<Figure> <Example resizable> { <>
  <p className="text-justify">
    Maybe we can live without libraries, people like you and me. Maybe. Sure, we're too old to change the world, but
    what about that kid, sitting down, opening a book, right now, in a branch at the local library and finding
    drawings of pee-pees and wee-wees on the Cat in the Hat and the Five Chinese Brothers? Doesn't HE deserve
    better? Look. If you think this is about overdue fines and missing books, you'd better think again. This is
    about that kid's right to read a book without getting his mind warped! Or: maybe that turns you on, Seinfeld;
    maybe that's how y'get your kicks. You and your good-time buddies.
  </p>
</>

} </Example>

html
<!-- [!code classes:float-none] -->
<article>
  
  <p>Maybe we can live without libraries, people like you and me. ...</p>
</article>
</Figure>

Responsive design

<ResponsiveDesign property="float">
html
<!-- [!code classes:md:float-left] -->

</ResponsiveDesign>