Arranging a Vertical Element Within a Rotated Holder

Who would have thought that geometry would come into play when working with CSS? I need help figuring out how to perfectly cover a rotated container with an upright background image. The goal is to hide the rotation on the sides and maintain dynamic control over sizing using percentages.

The blue line in the image represents the "wall" that the container needs to be stuck to. Since the image is upright, it needs to be larger than the container. I found a useful formula for this calculation here.

I'm struggling with calculating the various positionings within the design. Here's what it looks like without specific pixel values:

If anyone can help me understand how to calculate these distances, I'd greatly appreciate it.

For reference, here's my CodePen with the code written in SCSS: CodePen Link

body {
  padding: 2em 5em;
}

.wrapper {
  border-left: 3px solid blue;
}
.wrapper .container {
  opacity: 0.7;
  width: 300px;
  background-color: red;
  border-radius: 0 40px 40px 0;
  overflow: hidden;
  transform: rotate(10deg);
  margin-left: -42px;
}
.wrapper .container .sizing-wrapper {
  width: 100%;
  padding-top: 150%;
  position: relative;
}
.wrapper .container .img {
  position: absolute;
  top: 0;
  left: 0;
  background: url("http://placekitten.com/300/450") no-repeat right top;
  background-size: cover;
  height: 110.0573842629%;
  width: 124.5280657351%;
  transform: rotate(-10deg) ranslateY(-31px) translateX(-32px);
}
<div class="wrapper">
  <div class="container">
    <div class="sizing-wrapper">
      <div class="img"></div>
    </div>
  </div>
</div>

Answer №1

After sharing my question on Facebook, I received a solution from Amit Sheen that involved using transform-origin, which I initially overlooked. Surprisingly, it worked perfectly, making me wonder why I doubted its effectiveness in the first place.

Here is the revised CodePen link.

In order to ensure that the container aligns correctly with the wall, we must rotate it from the top left corner by adding transform-origin: 0 0.

Additionally, the image inside the container needs to be centered properly:

  .img {
    top: 50%;
    left: 50%;
    transform: rotate(-$deg) translateY(-50%) translateX(-50%);
    transform-origin: 0 0;
  }

I am still interested in exploring the mathematical solution to this problem, as I believe there is one. However, for practical purposes, this approach seems to be more effective...

body {
  padding: 2em 5em;
}

.wrapper {
  border-left: 3px solid blue;
}
.wrapper .container {
  opacity: 0.7;
  width: 300px;
  background-color: red;
  border-radius: 0 40px 40px 0;
  overflow: hidden;
  transform: rotate(10deg);
  transform-origin: 0 0;
}
.wrapper .sizing-wrapper {
  width: 100%;
  padding-top: 150%;
  position: relative;
}
.wrapper .img {
  position: absolute;
  top: 50%;
  left: 50%;
  background: url("http://placekitten.com/300/450") no-repeat right top;
  background-size: cover;
  height: 110.0573842629%;
  width: 124.5280657351%;
  transform: rotate(-10deg) translateY(-50%) translateX(-50%);
  transform-origin: 0 0;
}
<div class="wrapper">
  <div class="container">
    <div class="sizing-wrapper">
      <div class="img"></div>
    </div>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the functionality of the icon `<i>` in Twitter Bootstrap?

After adding an icon to a webpage, I noticed that it replaced the old, semi-deprecated <i> tag and instead used a customized image tag. It almost seems like <i ...> is just a simpler version of <img ...>. I'm curious about how this ...

Issues with Vertical Alignment and Navigation

Link: Please resize the browser to mobile view. Issue with Header: I am facing alignment issues in the header. The elements do not seem to be aligned properly at the center of the header. The Android logo is aligned, but the text and dash image are not. ...

Elevate a div over another div

I have a situation where I need to nest two divs inside another div with the ID "video-wrapper". Here is the HTML code: <div class="row"> <div class="video-wrapper col-lg-2"> <div class="video-thumbnail"> <img ...

Having trouble with Flowbite dropdown functionality in Next.js 12.* with Tailwind CSS

Hello, I am a newcomer to Next.js and currently working on a project using Tailwind/Flowbite. I copied and pasted the Flowbite search input with dropdown code from , but unfortunately, the dropdown is not functioning as expected. I have followed the docum ...

ever-evolving background-image with dynamic CSS styling

Being new to both PHP and Javascript, please excuse any mistakes in my explanation. I have information stored in a PHP array that I bring to my index page using the function below (located in a separate file called articles.php that is included in my index ...

Utilizing loop variables in ng-class and ng-click directive

This piece of code generates a list consisting of seven thumbnails, with the currently active image designated by the active and thumb classes. <div ng-repeat="no in [1, 2, 3, 4, 5, 6, 7]"> <img ng-src="images/{{no}}t.jpg" class="thumb" ng ...

Ways to hide menu click when hovering over it

As a beginner, I have created a menu that shows options on hover and click. However, I am encountering an issue where clicking on one menu option and then hovering over another menu creates two lists of options. Is there a way to make the clicked menu opti ...

Changing the Displayed Content with a Simple Click of a Link

Layout Overview In the process of developing a tool to streamline work tasks, I want to ensure that I am following best practices. My goal is for the website to initially display only column A, with subsequent columns generated upon clicking links in the ...

Is it possible to modify CSS properties by clicking on buttons?

Hello, I really need help with this task. I want to change the style of a button (which is actually a link) by clicking on it. These buttons are housed within a dynamic child div that changes each time, but the name of the dynamic child div remains con ...

What is the method for centering an input field with inline CSS?

Is there a way to center align an input text box on a webpage using only inline CSS? I have tried various techniques, including the following code snippet, but nothing seems to work: <input type="text" id="myInput" style= "margi ...

There are currently no articles found that match the search query

Recently, I started working with Django, but I am facing an issue with slug. Whenever I send a request to the Slug, I encounter an error. The error message I receive is: Articles matching query does not exist. Furthermore, I am facing another error while ...

What's the best way to make div columns appear closer together when floating?

Check out My CodePen: http://example.com/codepen Hello there, today I am working on a 6-column layout with 3 columns in each row. The 3rd column is quite long and resembles a sidebar. According to the design, columns 4 and 5 should be positioned close to ...

Automatic Full-Screen Switching Upon Video Playback in HTML5

Currently, I have a video clip set to play when the timer reaches a certain point. My goal is for the video to automatically enter full-screen mode when it starts playing and return to its original position when it stops, as the timer will continue ticking ...

Best practice for showcasing an MVC Form with the use of Bootstrap

I am facing an issue with my form layout while trying to capture user input. The use of Bootstrap is creating two columns for text boxes and their labels, but the alignment goes off track with the last EditorFor element. I'm questioning if I am misusi ...

What is the best way to showcase a div on top of all other elements in an HTML page?

As a newcomer to html and css, I have successfully created a div that contains city names. The issue I am currently facing is when I click on a button to display the div, it gets hidden behind the next section of my page. Take a look at the image below for ...

How to align several lines of text in a table cell

I've been trying to center multiple lines of text in a table cell using the table method, but no matter how many online guides and SO posts I follow, I just can't seem to get it right. What I'm aiming for is to have the text perfectly cente ...

HTML/CSS: Maintain Hover-Over Pop Up Boxes in Position Until Another Element is Hovered Over

Seeking HTML code to maintain a hover-over pop-up box in position on an image map until another section of the image map is hovered over. For example, refer to my code below - when hovering over a country on the map, a pop-up box with information about a ...

Generating dynamic divs in parallel

Despite encountering numerous posts related to the issue at hand, none of them have solved my specific problem. I am aiming for 3 divs to display in each row, but the current code is causing each div to show up on a new line vertically: JQuery ...

Tips for incorporating a background image using bootstrap

I am facing an issue with a large background image of size 1600 X 3700. When I try to add bootstrap to my project, the background image disappears and only the first 100px are visible. Can anyone provide guidance on the correct way to use bootstrap with ...

handling a radius variable across various stylesheets in SASS

Recently, I started using SASS and I am very impressed with this tool. However, before diving in further, I have one question that I can't seem to find the answer to. What is the best approach for managing a variable value across multiple style sheet ...