Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Responsive Design Utilities | Responsive and Advanced Styling
Styling React Apps with Chakra UI

bookResponsive Design Utilities

Stryg for at vise menuen

Chakra UI provides built-in responsive style props that allow components to adapt to different screen sizes without writing CSS media queries. Responsive values can be applied directly to component props using either array or object syntax.

The responsive array syntax assigns style values in order of Chakra UI breakpoints, starting from the base (smallest) screen size. For example, ["column", "row"] sets a layout to stack vertically on smaller screens and switch to a horizontal layout on larger screens.

The responsive object syntax uses named breakpoints such as base and md to explicitly define when styles change. This syntax improves readability by clearly indicating which styles apply at each breakpoint.

import { Box, Button, Heading, Input, Stack, Text } from "@chakra-ui/react"

export default function App() {
  return (
    <Box
      minH="100vh"
      bg="gray.50"
      color="gray.900"
      display="grid"
      placeItems="center"
      p={{ base: "4", md: "8" }}
    >
      <Box
        bg="white"
        borderWidth="1px"
        borderRadius="xl"
        p={{ base: "4", md: "6" }}
        w="full"
        maxW={{ base: "100%", sm: "420px" }}
      >
        <Stack gap={{ base: "3", md: "4" }}>
          <Heading size={{ base: "sm", md: "md" }}>
            Newsletter
          </Heading>

          <Text fontSize={{ base: "sm", md: "md" }} color="fg.muted">
            Get product updates once a week. No spam.
          </Text>

          <Input placeholder="Email address" size={{ base: "md", md: "lg" }} />

          <Button colorPalette="brand" size={{ base: "md", md: "lg" }}>
            Subscribe
          </Button>
        </Stack>
      </Box>
    </Box>
  )
}
question mark

Which syntax allows you to specify different style values for different breakpoints in Chakra UI?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 1

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Sektion 3. Kapitel 1
some-alt