乐闻世界logo
搜索文章和话题

How to get colored bullet list dots just using tailwindcss utility classes

1个答案

1

When using TailwindCSS, adding bullet points (i.e., the dots of a list) to list elements can be achieved with basic TailwindCSS utility classes. Here is a step-by-step guide:

  1. First, ensure TailwindCSS is installed and configured in your project.
  2. Next, apply the list-disc class to <ul> or <ol> elements to add bullet points.
  3. Then, use the list-inside class to position bullet points inside the content of list items, or list-outside to position them outside the content.
  4. Finally, customize list items as needed using utility classes like p-, m-, or text- for padding, margins, or text size.

Below is a practical example:

html
<ul class="list-disc list-inside m-4 p-2"> <li class="mb-2 text-blue-600">First item</li> <li class="mb-2 text-green-600">Second item</li> <li class="text-red-600">Third item</li> </ul>

Key explanations:

  • list-disc adds a circular bullet point before each <li> element.
  • list-inside positions bullet points within the content area of list items.
  • m-4 adds margin to the entire <ul> element.
  • p-2 adds padding to the entire <ul> element.
  • mb-2 adds bottom margin to each <li> element (except the last one).
  • text- classes set text colors for customization.

Following these steps allows you to create colored bullet points for lists using only TailwindCSS utility classes, with full styling flexibility.

2024年6月29日 12:07 回复

你的答案