CSS: Create a skewed layout using absolute positioning without using JavaScript !important

Is it possible to position a skewed element absolutely so that its left-bottom corner remains close (0px) to the container's border?

#one{
  position:absolute;
  background-color:darkkhaki;
  width:800px;
  height:200px;
  left:50%;
  transform: translateX(-50%)
}

#rect{
  position:absolute;
  background-color: salmon;
  width:400px;
  height:200px;
  left:50%;
  transform: translateX(-50%) skew(-25deg);
}

#marker{
  position:absolute;
  background-color:red;
  width:5px;
  height:200px;
  left: 200px;
}
<div id="one">
  <div id="rect"></div>
  <div id="marker"></div>
  <div>

I have indicated with a red line the position of the rectangle side before skewing it. I am trying to find a way to position the rectangle in such a way that its left-bottom corner aligns with the red line without using JavaScript. I cannot simply use 'left: Ypx' because the entire thing will be animated with keyframes (changing skew, rotateX + constant perspective on outer element).

Alternatively, can you suggest another method for creating an animation where pictures slowly "rise" from a lying-on-the-table position?

edit: CODEPEN

Answer №1

To achieve the desired effect, you can utilize the transform-origin Property. In this scenario, placing the <div id="marker"> inside <div id="rect"> and adjusting transform-origin to 0% 100% is the solution.

Refer to the following example:

#one{
  position:absolute;
  background-color:darkkhaki;
  width:800px;
  height:200px;
  left:50%;
  transform: translateX(-50%)
}

#rect{
  position:absolute;
  background-color: salmon;
  width:400px;
  height:200px;
  left:50%;
  transform: translateX(-50%) skew(-25deg);
}

#marker{
  position:absolute;
  background-color:red;
  width:5px;
  height:200px;
  top: 0px;
  left: 0px;
  transform: skew(25deg);
  -webkit-transform-origin: 0% 100%;
  transform-origin: 0% 100%;
}
<div id="one">
  <div id="rect">
     <div id="marker"></div>
  </div>
<div>

For a demonstration, view this Working Fiddle

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

Maximizing image size with dynamic height and automatic width using the NextJS Image Component

I am trying to set my images to have a fixed pixel height and automatic width using object-fit: contain. How can I achieve this with the NextJS Image Component without using layout="fill" so that the intrinsic width of the image (width: auto) is ...

Is it possible to combine two HTML tables by using JavaScript Objects as the source of data?

I have an array containing multiple arrays, and I want to create objects from each sub-array and then combine them into a single table. While I've been able to accomplish this, I'm looking for assistance on how to use these objects to create one ...

Conceal PHP variable using Cascading Style Sheets

Looking for a solution to this issue, but can't seem to find it anywhere! I need to hide the suffix variable from displaying using CSS or another method. When I simply remove it from the code, the whole site breaks for some reason. Here's the c ...

Analyzing data visualization within CSS styling

I have the desire to create something similar to this, but I am unsure of where to start. Although I have a concept in mind, I am struggling to make it functional and visually appealing. <div id="data"> <div id="men" class="shape"></di ...

Looks like Superfish's sf-js-enabled feature is experiencing some issues

I attempted to create a dropdown menu using Superfish, but unfortunately, it doesn't seem to be functioning as expected. I have ensured that all scripts and links are correctly directed to the appropriate js/css files. Additionally, I have implemented ...

Conflicting issues with jQuery's load() method

I am facing an issue with loading two HTML pages into a single div. I have index.html and try.html in the root folder, where try.html is loaded into index.html's div (#content) when Button 01 is clicked on index.html. The problem arises when I further ...

Tips for eliminating the white border in a stacked column Google chart

Is there a way to eliminate the white border in a stacked column google chart? If anyone has any tips or suggestions, please share! Here is an example of what I am referring to: my current chart ...

Ensuring Consistent Spacing Between Elements When Dealing with Varying Image Lengths

In order to clearly illustrate my need, I will provide some code here. .wrap{ display:flex; flex-direction:row; align-items: center; justify-content: flex-start; width: 100%; } .img{ width: 30px; height: 20px; background: red; } .img1{ ...

Create a Grid-Item-List with a custom arrangement, utilizing techniques like flex-box to achieve the desired layout

Struggling to create a unique grid-list that looks great on both desktop and mobile devices. Any tips or solutions would be greatly appreciated! I need a list (left image) with a special layout, which can be achieved through nested grids. However, I want ...

Showing an element using the PHP echo command by triggering a mouseover event on another element within the same echo statement

I am currently outputting data from a MySQL table using PHP and the "echo" command to display the results. I would like a certain element within the echo to be visible when I hover over another element within that same echo. The issue is that when I use ...

A method for locating the shadow's exact position

Can anyone assist me in determining the algorithm to calculate the position of a shadow based on the object's rotation? For instance, suppose I have a PNG image with -webkit-filter: drop-shadow(rgba(0, 0, 0, 0.5) Xpx Ypx 0px); and -webkit-transform: ...

Guide to horizontally aligning a div with a dynamic width in the center

After extensive research, I discovered that setting a width allows you to center a div using margin: 0 auto along with left: 0;, right: 0, and position: absolute. However, all the examples I found had a specified width. In my specific case, I need to cent ...

Ways to avoid scrolling on a fixed element

Here is the HTML setup I have... body .top .content The issue I am facing is that when scrolling reaches the end of the ul in the .top element, the background starts to scroll. This can be quite disorienting and makes the site slow on tablets. Even ...

Animating the maximum height causes a delay in the performance of other elements

Attempting to adjust the maximum height of a ul. When the max-height property changes (via toggling a class), the height shifts immediately, while the items below the ul maintain the animated height as expected. var expander = $('.skill-expand&apos ...

Reiterating the text and determining the length of the string

Currently, the script is capable of calculating the width of the script based on user input and can also determine the width of a string. However, I am facing an issue when attempting to repeat a string entered by the user. For example, if the user input ...

How can I hover over multiple cells in a table?

Is there a way to change the color of multiple adjacent cells when hovering over one cell, and can this be done dynamically (so the number of adjacent cells that change color can vary)? Here is the code snippet: I'm using React to create a table wit ...

Do I need to include both the JavaScript and CSS CDN for the bootstrap CDN to work properly, or can I just use one of them?

Which resource should I use for my project? Should I go with CSS, JS, BUNDLE or all of them? https://i.sstatic.net/0Yi3F.png I am interested in using button styling, grid, card components (and possibly dropdowns in the future) https://cdn.jsdelivr.ne ...

The Handsontable popup autocomplete editor is unfortunately truncated by the horizontal scrollbar

I have implemented an autocomplete feature on all columns in my project. However, I am facing an issue where the autocomplete editor gets cut off by the horizontal scrollbar. You can see the problem demonstrated in this jsfiddle link. Here is some code re ...

Is it feasible to organize checkboxes into columns using CSS?

Can checkboxes be reflowed into columns horizontally as the container's height changes dynamically with an unknown number of checkboxes? Here is a visual representation to illustrate the concept: Height = 180px (20px * 9 checkboxes): [ ] Checkbox 1 ...

Shifting text upwards within a document

I'm struggling with CSS and bootstrap as I have limited knowledge in this area. I have multiple divs on a page that I want to align based on our old website design. The problem I'm facing is that one div is larger on the right, causing a lot of ...