How To Change Elements Text Color By CSS Grouping Selector

admin_img Posted By Bajarangi soft , Posted On 28-10-2020

In CSS The grouping selector selects all the HTML elements with the same style definitions.Look at the following CSS code (the h1, h2, and p elements have the same style definitions).

How To Change Elements Text Color By CSS Grouping Selector

Step 1:Create Index.php file and implement below code.

 

<h2>Hello World!</h2>
<h3>Smaller heading!</h3>
<p>This is a paragraph.</p>



Step 2:Implement CSS to change text color.

 

<style>
    body {
        background: pink;
    }
    h2,h3, p {
        text-align: center;
        color: blueviolet;
    }
</style>




Complete Code To Change Elements Text Color By CSS Grouping Selector

 

<!DOCTYPE html>
<html>
<head>
    <title>How To Change Elements Text Color By CSS Grouping Selector</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<style>
    body {
        background: pink;
    }
    h2,h3, p {
        text-align: center;
        color: blueviolet;
    }
</style>
<body>
<br /><br />
<div class="container">
    <br><br><br>
    <div class="text-center">
        <h1 id="color" style="color: black;">How To Change Elements Text Color By CSS Grouping Selector</h1>
    </div>
    <br>
    <div class="well">
        <h2>Hello World!</h2>
        <h3>Smaller heading!</h3>
        <p>This is a paragraph.</p>
    </div>
    <br>
</div>
</body>
</html>

Related Post