mcadio's avatar

Weird overflow of text

I have a calendar, and I'm proud of it and how it works, functionality-wise, but I'm using Tailwind and I cannot seem to get the dang text to fit in the box when the time is 4 digits, such as 10:30 instead of 3 digits, like 9:30. The overflow is going to make me nuts.

I'm sharing the live site so you can see what I mean, and have access to the styling. It's easier than sharing all the components I'm using to put it together.

https://innerhealer.org/calendar

Does anyone know what I'm missing to get it to look good even for the longer times? I've tried flex-grow and items-stretch.

0 likes
4 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

It sounds like you're dealing with a CSS styling issue where the content is not fitting within its container properly. Since you're using Tailwind CSS, you can use a combination of utility classes to control text overflow.

Here's a solution that should help you prevent text from overflowing its container:

  1. Use the whitespace-nowrap utility to prevent the text from wrapping onto multiple lines.
  2. Use the overflow-hidden utility to hide any overflow.
  3. Optionally, use the text-ellipsis utility to add an ellipsis (...) to text that overflows.

Here's an example of how you might apply these classes to your calendar time slots:

<div class="w-full overflow-hidden whitespace-nowrap text-ellipsis">
  10:30
</div>

This will ensure that the text stays on one line, hides any overflow, and adds an ellipsis if the text is too long to fit in the box.

If you want the text to shrink to fit instead of hiding the overflow, you could use the text-xs, text-sm, or another text sizing utility to make the font size smaller for those elements.

For example:

<div class="w-full text-xs">
  10:30
</div>

You can adjust the text-xs to a different size based on your design needs.

If you're still having trouble, you might need to adjust the width of the container that holds the time text or consider a more responsive design where the container can grow with the content.

Remember to clear your cache and refresh the page to see the changes take effect. If you're still having issues, please provide more specific details about the HTML structure and the Tailwind classes you're currently using, so we can give a more targeted solution.

jlrdw's avatar

Try nl2br

On my computer screen all looks good.

kokoshneta's avatar

Not related to the question at all, but I would suggest adding a break between doctor names and hours. So instead of this (how it currently looks):

Dr. Carr Hours: 3:00 PM -
6:30 PM

– I’d have this:

Dr. Carr
Hours: 3:00 PM - 6:30 PM

If you put the hours inside a div/span styled with block whitespace-nowrap, you can make sure they don’t break across lines.

Also, Dr. Dave’s name/hours has a darker background (bg-blue-100) than his general area (bg-blue-50), whereas with Dr. Carr, both the general area and the name/hours are bg-pink-50. I’m assuming that’s an oversight, not intentional.

Please or to participate in this conversation.