CSS Opacity / TransparencyThe Show
Transparent ImageThe opacity 0.2 opacity 0.5 opacity 1 Transparent Hover EffectThe Example explainedThe first CSS block is similar to the code in Example 1. In addition, we have added what should happen when a user hovers over one of the images. In this case we want the image to NOT be
transparent when the user hovers over it. The CSS for this is When the mouse pointer moves away from the image, the image will be transparent again. An example of reversed hover effect: Transparent BoxWhen using the Transparency using RGBAIf you do not want to apply opacity to child elements, like in our example above, use RGBA color values. The following example sets the opacity for the background color and not the text: You learned from our CSS Colors Chapter, that you can use RGB as a color value. In addition to RGB, you can use an RGB color value with an alpha channel (RGBA) - which specifies the opacity for a color. An RGBA color value is specified with: rgba(red, green, blue, alpha). The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque). Tip: You will learn more about RGBA Colors in our CSS Colors Chapter. Example div { Try it Yourself » Text in Transparent BoxThis is some text that is placed in the transparent box. Example<html> div.transbox { div.transbox p { <div class="background"> </body> Try it Yourself » Example explainedFirst, we create a <div> element (class="background") with a background image, and a border. Then we create another <div> (class="transbox") inside the first <div>. The <div class="transbox"> have a background color, and a border - the div is transparent. Inside the transparent <div>, we add some text inside a <p> element. Basic usageLinear gradientsTo give an element a linear gradient background, use one of the
Applying conditionallyHover, focus, and other statesTailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use
For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation. Breakpoints and media queriesYou can also use variant modifiers to target media queries like responsive breakpoints, dark mode,
prefers-reduced-motion, and more. For example, use
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers. Using custom valuesCustomizing your themeBy default, Tailwind includes background image utilities for creating linear gradient backgrounds in eight directions. You can add your own background images by editing the These don’t just have to be gradients — they can be any background images you need. Learn more about customizing the default theme in the theme customization documentation. Arbitrary valuesIf you need to use a one-off
Learn more about arbitrary value support in the arbitrary values documentation. |