Horje
How to create Different Elements Can Share Same Class

Different HTML elements can point to the same class name.


Full Example of Different Elements Can Share Same Class

In the following example, both <h2> and <p> point to the "city" class and will share the same style:
index.html
Example: HTML
<!DOCTYPE html>
<html>
<head>
<style>
.city {
  background-color: tomato;
  color: white;
  padding: 10px;
} 
</style>
</head>
<body>

<h2>Different Elements Can Share Same Class</h2>

<p>Even if the two elements do not have the same tag name, they can both point to the same class, and get the same CSS styling:</p>

<h2 class="city">Paris</h2>
<p class="city">Paris is the capital of France.</p>

</body>
</html>

Output should be:

Full Example of Different Elements Can Share Same Class





Related Articles
What is HTML class Attribute HTML class Attribute
How to Use The class Attribute HTML class Attribute
How to use The Syntax For Class HTML class Attribute
How to create HTML Multiple Classes HTML class Attribute
How to create Different Elements Can Share Same Class HTML class Attribute
How to Use of The class Attribute in JavaScript HTML class Attribute

Single Articles
Full Example of Different Elements Can Share Same ClassHTML class Attribute

Read Full:
HTML class Attribute
Category:
Web Tutorial
Sub Category:
HTML class Attribute
Uploaded:
1 year ago
Uploaded by:
Admin
Views:
67


Reffered: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_classes_tags

Share on: