How To Change P Element Text Color By CSS Id Selector

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

The id selector uses the id attribute of an HTML element to select a specific element. The id of an element is unique within a page, so the id selector is used to select one unique element. To select an element with a specific id, write a hash (#) character, followed by the id of the element.

How To Change P Element Text Color By CSS Id Selector


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

<p id="para1">Hello World!</p>
<p>This paragraph is not affected by the style.</p>



Step 2: Implement CSS to change text color.
 

<style>
    #para1 {
        text-align: center;
        color: red;
    }
</style>



Complete Code To Change P Element Text Color By CSS Id Selector.

 

<!DOCTYPE html>
<html>
<head>
    <title>How To Change P Element Text Color By CSS Id 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;
    }
    #para1 {
        text-align: center;
        color: red;
    }
</style>
<body>
<br /><br />
<div class="container">
    <br><br><br>
    <div class="text-center">
        <h1 id="color" style="color: black;">How To Change P Element Text Color By CSS Id Selector</h1>
    </div>
    <br>
    <div class="well">
        <p id="para1">Hello World!</p>
        <p>This paragraph is not affected by the style.</p>

    </div>
    <br>
</div>
</body>
</html>

Related Post