How To Set Position For Background Image Using CSS

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

In CSS The background-position property is used to specify the position of the background image. So today we discuss how to do it.

How To Set Position For Background Image Using CSS

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

 

<h1>Hello World!</h1>
<p>We are setting background image to display only in Vertical</p>



Step 2:Implement CSS code as below to display images at specified position.
 

<style>
    body {
        background-image: url("../image/demo1.jpg");
        background-repeat: no-repeat;
        background-position: right top;
    }
</style>



Complete Code For Setting Position For Background Image Using CSS.
 

<!DOCTYPE html>
<html>
<head>
    <title>How To Set Position For Background Image Using CSS</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-image: url("../image/demo1.jpg");
        background-repeat: no-repeat;
        background-position: right top;
        margin-right: 200px;
    }
</style>
<body>
<br/><br/>
<div class="container">
    <br><br><br>
    <div class="text-center">
        <h1 id="color" style="color: black;">Set Position For Background Image Using CSS</h1>
    </div>
    <br>
    <div class="well">
        <h1>Hello World!</h1>
        <p>We are setting background image to display only in Vertical</p>
    </div>
    <br>
</div>
</body>
</html>

 

Related Post