Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

How to Rotate Container Background Image using CSS ?

  • Last Updated : 13 May, 2020

The CSS background-image property is used to add an image to the background of an element. In this article, the task is to rotate the image which is used in the background.

Approach: The CSS transform property is used to apply two-dimensional or three-dimensional transformation to a element. This property can be used to rotate, scale, move or even skew an element.

Syntax:

.class_name { transform: value } 

Example: We can use the CSS transform property to fix this issue and make rotations as given below:




<!DOCTYPE html>
<html>
  
<head>
    <!-- Bootstrap CDN -->
    <link rel="stylesheet"
          href=
  
    <!-- CSS -->
    <style>
        .background-image {
            background-image: url('Geeksforgeeks_image.jpg');
            background-repeat: no-repeat;
            height: 300px;
        }
          
        .rotated-background-image {
            background-image: url('Geeksforgeeks_image.jpg');
            background-repeat: no-repeat;
            height: 100%;
            margin-top: 250px;
            transform: rotate(90deg);
            /* All browsers support */
            -moz-transform: rotate(90deg);
            -webkit-transform: rotate(90deg);
            -o-transform: rotate(90deg);
            -ms-transform: rotate(90deg);
        }
          
        .custom {
            height: 100px;
            padding-top: 10px;
        }
    </style>
</head>
  
<body>
    <!-- Normal image which is not rotated -->
    <div class="container custom">
        <div class="background-image">
        </div>
    </div>
    <!-- Rotated image -->
    <div class="container">
        <div class="rotated-background-image">
        </div>
    </div>
  </body>
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :