CSS Layout

Switch

Credit - Frontend Master Phuoc Nguyen

TailwindCSS + ReactJS version of https://phuoc.ng/collection/css-layout/switch/

Please read the original blog for the rationale behind these solutions.


import clsx from 'clsx/lite';

export default function App() {
  return (
    <div>
      <label className={clsx(
        'flex rounded-full h-8 w-16',
        'bg-[#d1d5db] border border-[#d1d5db]',
        'mb-2' // for demo

      )}>
        <input type="checkbox" className='hidden' />
        <div className='w-8 bg-white rounded-full' />
      </label>

      <label className={clsx(
        'flex rounded-full h-8 w-16',
        'bg-[#357edd] border border-[#357edd] justify-end'
      )}>
        <input type="checkbox" className='hidden' />
        <div className='w-8 bg-white rounded-full' />
      </label>
    </div>
  );
}
Last Update: 11:59 - 22 April 2024

On this page

No Headings