Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Text with Divider in ChakraUI

I am using ChakraUI for one of my projects and I want to add a Text with Divider like this:
Text with divider

In ChakraUI, I could do this:
my way of text with divider

and code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<Flex alignItems={"center"}>
    <Heading as="h4" size="lg">
          About the Department
    </Heading>
    <Divider border="4px" borderRadius={"2xl"} />
</Flex>

but I want to show the text in one line.

Although I could still use like this:

<Flex alignItems={"center"}>
    <Heading as="h4" size="lg">
          About&nbsp;the&nbsp;Department
    </Heading>
    <Divider border="4px" borderRadius={"2xl"} />
</Flex>

which will make the text in one line.

So I am wondering is there any way to show text in one line? as shown in the first example.

>Solution :

Perhaps try add whiteSpace: "nowrap" to Heading.

A quick minimized demo: stackblitz

Example:

<Flex alignItems="center" gap={6}>
  <Heading as="h4" size="lg" sx={{ whiteSpace: "nowrap" }}>
    About the Department
  </Heading>
  <Divider border="4px" borderRadius={"2xl"} />
</Flex>

An optional gap={6} is also added on Flex here to create a small gap between the Heading and Divider, but can be customized to fit the use case.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading