How To Set Fixed Position For HTML Element Using CSS

admin_img Posted By Bajarangi soft , Posted On 03-11-2020

The position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element.A fixed element does not leave a gap in the page where it would normally have been located.So Today we discuss how to do it.

How To Set Fixed Position For HTML Element Using CSS

Step 1:Create index.html file and implement as below code in it.

<p class="fixed">This is Paragraph</p>

Step 2: Implement CSS code as below to set p element at Fixed  position.

<style>
    body {
        background: #2e9ad0;
    }
    .fixed {
        position: fixed;
        bottom: 100px;
        right: 0;
        width: 300px;
        border: 3px solid #73AD21;
    }
</style>

Complete Code For Setting Fixed Position For HTML Element Using CSS.

<!DOCTYPE html>
<html>
<head>
    <title>How To Set Fixed Position For HTML Element Using CSS</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <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: #2e9ad0;
    }
    .fixed {
        position: fixed;
        bottom: 100px;
        right: 0;
        width: 300px;
        border: 3px solid #73AD21;
    }
</style>
<body>
<br/><br/>
<div class="container">
    <br><br><br>
    <div class="text-center">
        <h1 id="color" style="color: white;">Set Fixed Position For HTML Element Using CSS</h1>
    </div>
    <br>
    <div class="well">
        <p class="fixed">This is Paragraph</p>
    </div>
    <br>
</div>
</body>
</html>

Related Post