Then, the use or function of the multiple classes is explained. First, we explained the creation and use of class in CSS internal and external styling. In this guide, we tried to explain the concept of the multiple classes in CSS. If two same properties are applied in different classes, the effect that is applied later is implemented. This is because CSS has an overlapping effect capacity. Furthermore, one thing is questionable: as the second and third divs implemented the one class and the second third, why is the color of the “one” div not applied to both?
The second and third divs are displaced because they both used the one class as an additional with them. The first div is not shifted from the left this is because the “one” class has no margin property. Upon execution, you will see that all the three divs are of the same height and width.
Save the whole code and execute the file in the browser. The rest of the two classes, two and three, have two properties. As we have seen that all the three divs used this class, it means that these effects are applied to all of them by having the same height and width. The class “one” contains the background color, the font color width, and the height of the div. Inside the head section, a style tag is used and all the three classes are declared. It means that one class is written in all three divs.Īdd the text inside the div and close all the opened tags. And the third class contains one and three. The second div is accompanied by the class names of one and two. The first div contains the class one only. Each time, we use the different class names inside the tags. Now, we apply this multiple class effect to the div containers. Example 2: Multiple Class Effect on Div Container The second class only has the first class name, so it is affected only by that background property written in the class one. As the first paragraph contains both the class name, the background color and the padding effect are applied. This change in effects is because of the difference in the use of the class. Whereas the second paragraph has the background but it is aligned to the left. Upon execution, you will see that the first paragraph has the background written away from the left because of the padding effect. By doing this, you will be able to execute the text as a web page in the editor. Inline CSS is preferable when a single property value is to be applied to the HTML tag.Īfter that, close the style tag and the head section. That is the reason that the developers prefer the internal or external styling on inline CSS because we can apply more than one effect at a time on the different HTML contents rather than writing each effect separately inside the HTML tag. Inside the class, we can write several properties that we want to be applied to the HTML contents. For example, “.sample” is the name of a class. Id and class are declared inside the style tags either they are declared in the head section or outside the file in another text file with a CSS extension. To apply the initial and external CSS types, we use the two basic approaches. In this article, we will discuss the effect that is applied to the internal and external CSS only, that is the CSS class. A Cascading Style Sheet that is used with the HTML language is divided into three main types: inline, internal and external CSS.