html

Wildcard * in CSS for Class

In CSS, there are numerous selectors utilized for different purposes, including wildcard selectors, id selectors, class selectors, and many more. More specifically, the wildcard selector chooses multiple elements at once. It selects class names or characteristics of a similar type and assigns CSS properties. Whenever users employ this wildcard selector in CSS, all items with the same class name will get selected.

This post will demonstrate the usage of wildcard * in CSS for class.

How to Utilize the Wildcard * in CSS for Class?

To utilize the wildcard * in CSS for class, try out the mentioned procedure.

Step 1: Insert a Heading
First of all, add a heading by utilizing the heading tag. To do so, we will add the “<h1>” tag.

Step 2: Create div Containers
Create three separate div containers with the help of the “<div>” element and insert a “class” attribute in each container with a specific name according to your preferences.

Step 3: Add Text
Next, utilize the “<p>” tag to insert text in the form of a paragraph. Also, add a “class” attribute with a unique name. Then, embed a text in between the paragraph tag:

<h1>Linuxhint LTD UK</h1>
 <div class="main-div">
  <div class="str-first"> First Container</div>
  <div class="str-second">Second Container</div>
  <div class="str-third">Third Container</div>
  <p class="content">linuxhint provides the content for various categories, including docker, HTML/CSS, Discord, Powershell, Windows, Git hub and many more.</p>
 </div>

Output

Step 4: Access the “str” Class by Utilizing the * Wildcard
Then, specifying “[class*= “str”]” will select all the div elements whose class name starts with “str”:

[class*="str"]{
 background: rgb(80, 119, 250);
 color: white;
}

Then, apply the following CSS properties on all selected elements:

  • background” property sets the color for the background of the element.
  • color” allocates the specific color for the element.

Step 5: Style Heading
Access the heading with the help of the “<h1>” tag:

h1 {
 color:rgb(44, 3, 230);
 text-align: center;
}

After that, the “color” property is applied to make the heading colorful and set the “text-align” property value as “center” to center align the text.

Step 6: Style “main-div” Container
Access the main div container by utilizing the dot selector with the class name “.main-div”:

.main-div {
 align-items: center;
 text-align:center;
 width:60%;
 margin-left: 80px;
 border: 2px solid blue;
}

In the above code snippet:

  • align-items” property sets the alignment of the element as “center”.
  • text-align” is utilized for allocating the alignment of the text in the element.
  • align-items” property sets the alignment of the element as “center”.
  • margin-left” sets the margin from the left side of the element.
  • border” defines a boundary outside the element having a proper width, style, and color.

Output

That’s it! You have learned about the wildcard * in CSS for class.

Conclusion

The wildcard “*” in CSS is a selector that is utilized for selecting all elements according to the defined value. After selecting them, you can apply a single styling layout to all elements. This approach is useful when it is required to style multiple elements having the same class value. This write-up has explained the wildcard * in CSS for the class.

About the author

Hafsa Javed