Classe de cores de fundo Tailwind: um guia completo

Neste artigo, exploraremos a classe Tailwind Background Color com mais detalhes, incluindo os valores disponíveis e as práticas recomendadas para usá-la com eficiência.

As cores de fundo são um aspecto crucial do design da web, pois podem ajudar a definir o tom e o humor de uma página da web, fornecer hierarquia visual e até mesmo transmitir a marca.

No Tailwind CSS , a classe Background Color é um utilitário versátil e poderoso que fornece uma maneira rápida e fácil de definir a cor de fundo de um elemento.

Cor de fundo do vento de cauda



Cor de fundo do vento de cauda

Tailwind CSS oferece um conjunto abrangente de classes para definir a cor de fundo dos elementos HTML.

Essa classe é uma alternativa à propriedade CSS background-color e cobre todas as variações possíveis.

Ao usar a classe de cor de fundo do Tailwind, você pode definir facilmente a cor de fundo de um elemento, incluindo seu preenchimento e borda.

Sintaxe

<element class="background-{color}"></element>

Valores de cores de fundo do Tailwind

  1. background-transparent : define a cor de fundo como transparente.
  2. background-current : A cor de fundo depende da cor do elemento pai.
  3. background-black : Define a cor de fundo para preto.
  4. background-white : Define a cor de fundo para branco.
  5. background-gray-{intensity} : define a cor de fundo para um tom de cinza. O valor {intensity} varia de 50 a 900, sendo 50 o mais claro e 900 o mais escuro.
  6. background-red-{intensity} : Define a cor de fundo para um tom de vermelho.
  7. background-blue-{intensity} : Define a cor de fundo para um tom de azul.
  8. background-indigo-{intensity} : define a cor de fundo para um tom de índigo.
  9. background-purple-{intensity} : Define a cor de fundo para um tom de roxo.
  10. background-green-{intensity} : Define a cor de fundo para um tom de verde.
  11. background-yellow-{intensity} : Define a cor de fundo para um tom de amarelo.
  12. background-pink-{intensity} : Define a cor de fundo para um tom de rosa.

Para usar a classe de cor de fundo, adicione a classe background-{color} ao elemento, onde {color} é a cor de fundo desejada.

Abaixo estão exemplos de como usar as classes de cores de fundo do Tailwind :

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<div class="mx-14 bg-green-200 text-center p-4 font-semibold">
<p class="bg-transparent p-2 border-2 border-slate-400">
bg-transparent
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Este é um exemplo da classe bg-current :

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<p class="font-semibold my-2">Text is same color as background</p>
<p class="font-medium text-sm text-gray-600 my-2">You can highlight the text using your mouse</p>
<div class="mx-14 bg-gray-200 text-center p-4 font-semibold">
<p class="bg-current text-red-500 p-2">
bg-current
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Usando bg-black como exemplo:

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<div class="mx-14 bg-green-200 text-center p-4 font-semibold">
<p class="bg-black text-white p-2">
bg-black
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Usando bg-white como exemplo:

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<div class="mx-14 bg-gray-200 text-center p-4 font-semibold">
<p class="bg-white p-2">
bg-white
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Como exemplo, aqui está uma classe bg-gray-400 em uso:

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<div class="mx-14 bg-green-200 text-center p-4 font-semibold">
<p class="bg-gray-400 p-2">
bg-gray
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Este é um exemplo da classe bg-red-700 :

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<div class="mx-14 bg-green-200 text-center p-4 font-semibold">
<p class="bg-red-700 p-2">
bg-red
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Usando bg-blue-700 como exemplo:

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<div class="mx-14 bg-green-200 text-center p-4 font-semibold">
<p class="bg-blue-700 p-2">
bg-blue
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Como exemplo, aqui está uma classe bg-indigo-700 em uso:

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<div class="mx-14 bg-gray-200 text-center p-4 font-semibold">
<p class="bg-indigo-700 p-2">
bg-indigo
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Usando bg-purple-700 como exemplo:

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<div class="mx-14 bg-green-200 text-center p-4 font-semibold">
<p class="bg-purple-700 p-2">
bg-purple
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Usando bg-green-700 como exemplo:

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<div class="mx-14 bg-gray-200 text-center p-4 font-semibold">
<p class="bg-green-700 p-2">
bg-green
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Veja a seguir um exemplo usando a classe bg-yellow-400 :

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<div class="mx-14 bg-green-200 text-center p-4 font-semibold">
<p class="bg-yellow-400 p-2">
bg-yellow
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Veja a seguir um exemplo usando a classe bg-pink-500 :

Example: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html><head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="text-center mx-4 space-y-2">
<h1 class="text-gray-600 text-2xl font-semibold">
MrExamples
</h1>
<p class="font-semibold my-2">Background Color Class in Tailwind CSS</p>
<div class="mx-14 bg-gray-200 text-center p-4 font-semibold">
<p class="bg-pink-500 p-2">
bg-pink
</p>
</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Vale a pena notar que quando você usa a classe background-current, a cor de fundo será a mesma que a cor do texto.

Isso significa que o texto ficará invisível , mas ainda estará presente no código HTML.

Nós valorizamos o seu feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Assine a nossa newsletter
Digite seu e-mail para receber um resumo semanal de nossos melhores posts. Saber mais!
ícone