Umar Shahzad
Umar Shahzad

Reputation: 1

How to rotate outer div not inner content

How to fit an image inside a div and this div is rotated at 45deg?

Upvotes: 0

Views: 1251

Answers (2)

Mordecai
Mordecai

Reputation: 1494

Add scale value in transform style for img like this:

.profile-photo { width: 210px; height: 210px; position: relative; left: 43px; top: 50px; border: 8px solid #000; border-radius: 60px; transform: rotate(45deg); overflow: hidden; z-index: 2; background: #34983e;padding:0 }

.profile-photo img {
  width: 100%;
  transform: rotate(-45deg) scale(1.21)
}
<div class="profile-photo"> 
  <img alt="Profile photo" src="http://www.michiganurology.com/wp-content/uploads/2015/10/reddy.jpg" onerror="this.onerror=null;this.src='https://via.placeholder.com/500/E5E8EC/4B89DA?text=error+image';">
</div>

Upvotes: 4

Pallamolla Sai
Pallamolla Sai

Reputation: 2493

use below code.

HTML

<div class="div">
    <img src="index.png">
</div>

CSS

.div
    {
        width: 500px;
        background: lightblue;
        transform: rotate(40deg);
    }

W3schools transforms

Upvotes: -1

Related Questions