DocsBlog
  • 1.7.0

  • Day

    Night

    Preview

    Switch mode
  • Cerberus

    Acheron

    Elysium

    Oceanus

Get Started
Components
Data Grid
Signals
Styling
Theming

Concepts

OverviewCompositionCerberus ContextTesting

Layout

Aspect RatioBleedBoxCenterContainerContainer QueryDividerFlexFloatGridGroupLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMarqueeNotificationsNumber InputPaginationPin InputPopoverProgressPrompt ModalRadioRatingSelectSliderSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsTheme

Container Query

Apply styles to an element based on certain attributes of its container.

  • Panda
import { Cq } from "styled-system/jsx"

Usage

The Cq component is used to apply styles based on the width of the container. This is a useful alternative to media queries which are based on the width of the browser viewport.

Cq provides two utility props:

  • name: The name of the container query, Maps to the containerName CSS property.
  • type: The type of the container query. Maps to the containerType CSS property. Defaults to inline-size.

The container query size conditions use the following syntax: @/[size] or @[custom-name]/[size]

Name

The name prop is used to define the name of the container query. This must be defined in the Panda config in order to use it on the Cq component.

Once "registered", the name prop can be used to add container-specific boundaries and styles.

Step 1: Register container names and sizes

export default createCerberusConfig({
    // ...
    theme: {
      extend: {
        containerNames: ['sidebar', 'content'],
        containerSizes: {
          xs: '40em',
          sm: '60em',
          md: '80em'
        }
      }
    }
  })

Step 2: Use Cq to apply container query styles

import { Box, Cq } from 'styled-system/jsx'

  export function UsageDemo() {
    return (
      <Cq name="sidebar">
        <Box
          fontSize={{
            base: 'lg',
            '@sidebar/sm': 'md',
          }}
        />
      </Cq>
    )
  }

Type

The type prop is used to define the type of the container query. Defaults to inline-size.

Guide

Default Sizes

The following sizes are included with Cerberus by default:

{
  xs: '320px',
  sm: '384px',
  md: '448px',
  lg: '512px',
  xl: '576px',
  '2xl': '672px',
  '3xl': '768px',
  '4xl': '896px',
  '5xl': '1024px',
  '6xl': '1152px',
  '7xl': '1280px',
  '8xl': '1440px'
}

Props

The Cq component supports all CSS properties as props, making it easy to style elements.

On this page

Loading...

Loading...

Loading...

Loading...

Responds to the container size change - resize the browser to see
Responds to the container size change - resize the browser to see
Responds to the container size change - resize the browser to see
Copy
Responds to the container size change - resize the browser to see
Responds to the container size change - resize the browser to see
Responds to the container size change - resize the browser to see
Copy
import { DecorativeBox } from '@/app/components/decorative-box'
import { Cq, VStack } from '@/styled-system/jsx'

export function BasicDemo() {
  return (
    <VStack gap="lg" mx="md" w="full">
      <Cq w="full">
        <ContainerBox />
      </Cq>

      <Cq mx="md" w="1/2">
        <ContainerBox />
      </Cq>

      <Cq mx="md" w="1/3">
        <ContainerBox />
      </Cq>
    </VStack>
  )
}

function ContainerBox() {
  return (
    <DecorativeBox
      bgColor={{
        base: 'action.bg.initial',
        '@/sm': 'info.surface.initial',
        '@/md': 'warning.surface.initial',
      }}
      color={{
        base: 'action.text.initial',
        '@/sm': 'info.text.100',
        '@/md': 'warning.text.100',
      }}
      h="200px"
      p="md"
      textAlign="center"
    >
      Responds to the container size change - resize the browser to see
    </DecorativeBox>
  )
}
import { DecorativeBox } from '@/app/components/decorative-box'
import { Cq, VStack } from '@/styled-system/jsx'

export function TypeDemo() {
  return (
    <VStack gap="lg" mx="md" w="full">
      <Cq type="normal" w="full">
        <ContainerBox />
      </Cq>

      <Cq type="normal" mx="md" w="1/2">
        <ContainerBox />
      </Cq>

      <Cq type="normal" mx="md" w="1/3">
        <ContainerBox />
      </Cq>
    </VStack>
  )
}

function ContainerBox() {
  return (
    <DecorativeBox
      bgColor={{
        base: 'danger.bg.initial',
        '@/sm': 'indigo',
        '@/md': 'purple',
      }}
      h="200px"
      p="md"
      textAlign="center"
    >
      Responds to the container size change - resize the browser to see
    </DecorativeBox>
  )
}

On this page

  • Usage
  • Name
  • Type
  • Guide
  • Default Sizes
  • Props
  • Edit this page on Github