CSS Container with a Tilted Background Image

Trying to set up a rotated container that can display a background image while maintaining the original proportions without skewing it, only cropping.

Referencing the following code snippet: http://jsfiddle.net/RyU9W/38/

HTML:

<div id="container" class="color-container">
    <p>Colored Container</p>
</div>

<div class="sep"></div><div class="sep"></div>

<div id="container" class="image-container">
    <p>Image Container</p>
</div>

CSS:

p {padding: 250px 0;}
.sep {margin: 250px 0;}

#container {
    background:none;
    position:relative;
}

#container:before {
    content: "";
    position:absolute;
    display:block;
    width:100%;
    height:100%;
    padding: 100px 0;
    z-index:-1;
    -webkit-transform: skew(0deg, 4deg) translateZ(0);
    transform: skew(0deg, 4deg) translateZ(0);
}

.color-container:before {
    background: royalblue;
}

The colored container is functioning correctly, but encountering issues with rotating the image container as intended. Seeking guidance on how to resolve this challenge.

Any assistance would be greatly appreciated!

Answer №1

Make sure to implement the transformation onto the img element. Furthermore, ensure that each #container division has a distinct ID. Note: Remove the overflow hidden property from the backstretch container to reveal the skewed content at the bottom of the image.

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

The link button appears unselected without a border displayed

I am facing an issue with a link button in my code. Here is the snippet: <div class="col-2"> <a type="button" routerLink="auto-generate-schedules/generate" class="btn btn-primary mb-2">Generate Sche ...

Gradually alter the content within the div while transitioning the background color

I'm working with a div that has the following CSS properties: #results { background: #dddada; color: 000000; cursor: pointer; } #results:hover { background: #3d91b8; color: #ffffff; } How can I smoothly change just the text inside this div, u ...

Having trouble with Bootstrap form-inline stacking issue, any tips on how to stop them from stacking?

I've created a simple test navbar with a search input box and search button using the Bootstrap class form-inline. However, the search button is appearing below the search input, even though there is enough space available. You can view the codepen he ...

Design a stylish outline for the element <div class="loader">

Initially, I managed to create a border around the body without any issues. However, I encountered a problem when attempting to implement a rotating border animation. In order to achieve this, I had to create a div encompassing all my content. The issue ar ...

Providing space for a two-line title

It's a bit tricky to explain, so if anyone has a better title in mind, feel free to change it. I'm trying to create a black box behind my headline. I'm using a span inside the h-tag for this purpose, but I need to add some padding to the le ...

Difficulty encountered in setting the width of a sticky bottom element to be located at the bottom of the page with Tailwind

Fiddle: https://play.tailwindcss.com/pvT1jW8zZd Here is the code snippet I am working with: Here is how it currently appears: https://i.sstatic.net/2SRny.png <div class="bg-yellow-300"> <div class="p-16 m-5 text-xl bg-gray-500 ...

Integration of JavaScript files in HTML leads to the disappearance of the slider component

After adding two sliders to my web page, I noticed that only one of them is working when I link all the necessary JavaScript files into the HTML page. It seems that the new JavaScript files for the second slider are causing the first slider to not show up ...

Eliminate resistance on HTML components

Have you ever noticed that when you click on an HTML element, such as images, you can drag a "shadow version" of them around on the screen? For example, take the Stack Overflow logo. If you click and drag it, you'll see a dark version of the logo mov ...

Utilizing CSS flex-end to position images

I am facing an issue with aligning the last item in my container named section-a. The height of the container is set to 100vh and it contains 3 items. I have tried using the property align-self:flex-end, but there are no visible changes. Can anyone help me ...

Displaying varied information based on JSON feedback using AngularJS

I am currently in the process of developing an app using AngularJS and the Ionic framework. The app will display a list of data with various subcategories for each item, depending on the account type. View sample image here The issue I am facing is that ...

Can someone please tell me the specific HTML entity that Flickr uses for the arrow icons in the action menu?

When viewing an image on FLickr () and clicking on the Actions menu button, a pop-up menu with an arrow icon appears. Interestingly, this icon is not a simple image, but rather a combination of two characters (◢◣). Has anyone been able to determine th ...

Expanding the width of a child element causes it to exceed the boundaries of its parent

When I increase the width of a child element, it sometimes goes outside the boundaries of its parent element. The child element tends to only expand towards the right side, so I tried using the float property on the child element. Is there a CSS trick that ...

What is causing the table to not be displayed in this Javascript program when it is used in a

I am currently experimenting with incorporating an infinite loop before the prodNum and quantity prompts to consistently accept user input and display the output in a table. Although the program is functional when executed, it fails to showcase the table ...

Having trouble with the rounded-circle class in Bootstrap 5?

@import url('https://myfonts.com/css?family=Roboto&display=swap'); body { background: #f1f2fa; font-family: 'Roboto', sans-serif; } hr { border: 2px solid #0b5ed7 } .crd { background: #f1f2fa; transition: all; ...

Implementing a feature that ensures html elements are transparent in a PDF conversion

I am in the process of converting a webpage into a format that is easily printable as a PDF, while ensuring that it maintains the same appearance. Many tools for printing to PDF do not support background images or colors, so I am attempting to overcome thi ...

Combine going to an anchor, performing an AJAX request, and opening a jQuery-UI accordion tab all within a

My goal is to have the user click on the hyperlink below, which will (1) anchor to #suggestions, (2) navigate to the url suggestions.php?appid=70&commentid=25961, and (3) open the jquery-ui accordion #suggestions. However, I am facing an issue where c ...

Ensure the proper fit for smaller screens

While using Bootstrap 4 and incorporating Stream UI Kit for the user interface within my application, I've encountered an issue where the column size doesn't display correctly on smaller screens! For example: https://i.sstatic.net/mUekg.png On ...

Duplicate the appearance of a webpage exactly as it is displayed, without regard to the underlying source code

Looking to transfer content from a webpage to a Word document? Specifically, an installation guide, with additional comments about our own installation process. Seems easy enough - just copy and paste, right? Not quite. The issue lies in the structure of ...

Showing the name of a class

Hello everyone, I have a piece of JavaScript code that generates HTML buttons when the page loads. The button attributes are fetched from a database through an ASP page. Everything is working fine except for displaying the class attribute - it shows as u ...

What is the best way to swap the values of options between two input select elements?

I am trying to create a feature where I have two select dropdowns with the same options, and when a trigger is clicked, the option values are inverted between the two selects. Here is an example: <select id="source_currency"> <option value="BRL" ...