Adjust the angle and trim an image on one side

Can someone assist with making an image appear like this:

https://i.sstatic.net/J4DPp.jpg

I'm attempting to achieve this look using CSS:

https://i.sstatic.net/fuucK.png

I've experimented with skewing but the red area persists, regardless of the degree value used.

Here is my basic structure:

<div class="wrapper">
    <div class="trapec">
        <div class="image"></div>
    </div>
  </div>

For styling, I referred to this example: http://jsfiddle.net/mXLgF/477/

My CSS:

.wrapper  {
        width: 530px;
        background: rgba(180, 180, 180, 0.7);
        position: relative;
        height: 230px;
    }

.wrapper .trapec{
        position: absolute;
        left: 0;
        width: 325px;
        height: 100%;
        overflow: hidden;
        -webkit-transform: skew(20deg);
        -moz-transform: skew(20deg);
        -o-transform: skew(20deg);
    }

    .wrapper .trapec .image {
        width: 100%;
        height: 100%;
        -webkit-transform: skew(-20deg);
       -moz-transform: skew(-20deg);
         -o-transform: skew(-20deg);
        background: url("../img/news_img.jpg") no-repeat center / cover;
    }

Despite trying various degree values, I cannot eliminate the persistent red line. Ask for guidance please.

Answer №1

To achieve this effect, you can utilize the :before pseudo css selector. It is advisable to use the <img> tag instead of relying on the background-image property.

Make sure to adjust the value in the skew() function based on your specific requirements.

Access the Updated Fiddle Here

Check out the Stack Snippet below:

.container {
  overflow: hidden;
  margin-left: 40px;
}

#parallelogram {
  width: 300px;
  height: 300px;
  overflow: hidden;
  position: relative;
}

img {
  max-width: 100%;
}

#parallelogram:after {
  content: "";
  top: 0;
  left: 100%;
  width: 100%;
  bottom: 0;
  background: #000;
  position: absolute;
  transform: skew(30deg);
  transform-origin: bottom;
  background: #fff;
}
<div class="container">
  <div id="parallelogram">
    <img src="http://lorempixel.com/300/300/sports" alt="">
  </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

Triggering a JQuery event to switch between tabs

Currently, I am in the process of developing a web application that incorporates nav-tabs from Bootstrap. These nav-tabs consist of 4 different tab-contents. My main concern lies in determining which nav-tab the user has selected among the 4 tabs and updat ...

Tips for Keeping a Responsive Image at the Forefront of a Text-Image Layout as You Scroll

I'm currently in the process of creating a website where text appears on the left side with an accompanying image on the right. The challenge I'm encountering is ensuring that as users scroll, the image adjusts dynamically based on the associated ...

Issues encountered while attempting to convert HTML Image and Canvas Tags to PDF within Angular 2

I am currently facing an issue with my code. My requirement is to download HTML content as a PDF file. I have been successful in downloading text elements like the <p> tag, but I am encountering difficulties when trying to download images and canvas ...

Is it possible to dynamically pass a component to a generic component in React?

Currently using Angular2+ and in need of passing a content component to a generic modal component. Which Component Should Pass the Content Component? openModal() { // open the modal component const modalRef = this.modalService.open(NgbdModalCompo ...

Leverage the power of JavaScript validation combined with jQuery

Hello, I'm relatively new to the world of Javascript and jQuery. My goal is to create a suggestion box that opens when a user clicks on a specific button or div element. This box should only be visible to logged-in users. I have some knowledge on how ...

Show the selected row's data from a gridview in a dropdown menu

I am facing an issue with displaying the selected row value in a dropdown list. Can anyone assist me with this problem? Here is an example scenario: https://i.sstatic.net/RYssP.png Upon looking at the image, you will notice that the selected row's ...

Tips on how to showcase various information in distinct tabs using VueJS

I am currently working on a website project utilizing the VueJS framework and Vuetify template. My goal is to showcase different content under separate tabs, however, I'm encountering an issue where the same content is being displayed in all three tab ...

A guide on updating CSS content dynamically within ExtJS

In my resource folder, I have a CSS file that contains some values which I need to change or add based on certain conditions. However, I'm struggling to figure out how to achieve this. Here is an example of the code: triggers: { clear: { ...

To prevent flickering when using child flex elements, it's best to use position fixed along with a dynamically updated scrollbar position using Javascript

My navigation component includes a slim banner that should hide upon scroll and a main-nav bar that should stick to the top of the screen and shrink when it does so. I initially looked into using Intersection Observer based on a popular answer found here: ...

I'm looking to make my PayPal donate button smaller after noticing that PayPal is making it larger. How can I adjust the size of my customized PayPal

I am seeking your help in resolving an issue with PayPal enlarging my button from 130px x 65px to 300px x 150px. I have checked the button on both a local browser and within the Square Space editor, but the result remains the same. I even attempted to adju ...

Scrolling the inner container in a CSS flexbox layout: tips and tricks

I'm currently working on designing a flex box based HTML layout like the one shown in the image link provided below. https://i.stack.imgur.com/nBl6N.png The layout should consist of 3 rows within the viewport with the following structure: - top: " ...

What is the reason behind the lack of collapsing in an inline-block container that only contains floated items?

Within this design, there are 3 boxes arranged in a row using the float: left; property for each one. These boxes are contained within 2 other elements. Typically, these containers collapse due to the content being comprised of floated items. However, chan ...

Setting the maximum height for a tr or td element that is compatible with Chrome

Is there a way to set the max-height for a tr or td element that is specifically supported in Chrome? Previously, an answer suggested at this link did not work for Chrome: How to fix height of TR? ...

When a form contains a ViewChild element, changes to the ViewChild element do not automatically mark the

Let's set the stage: MainComponent.html <form #someForm > <input type="text" name="title" [(ngModel)]="mainVar" /> <child-component /> <input type="submit" [disabled]="someForm.form.pristine" /> </form> ChildComp ...

IE7 is not applying the conditional CSS styles to content loaded through AJAX

I am currently tackling some challenges with IE7 compatibility in a Rails application that I am developing. It appears that CSS styles implemented from a stylesheet applied with a conditional comment are not being rendered properly when using HAML like thi ...

Incorrect behavior of responsive background images

For the first time, I am working on a school project that requires me to create a responsive website. I am following the "mobile first" approach. On stackoverflow, I came across a helpful way of making background images responsive: background-image: url(. ...

Deactivate user input depending on a certain requirement

Greetings everyone, I am currently working with the following code snippet: <table class="details-table" *ngIf="peop && peopMetadata"> <tr *ngFor="let attribute of peopMetadata.Attributes"> <td class="details-property"&g ...

What is the correct way to display a URL in Jupyter Lab?

This is a direct link for searching the keyword "google" on google.com: https://www.google.com/search?q=google&rlz=1C1CHBD_elGR899GR899&oq=google&aqs=chrome..69i57j69i60l4j69i65l2j69i60.1647j0j7&sourceid=chrome&ie=UTF-8 When I run the ...

Utilize Flexbox to create a layout with 3 divs, organized into two columns where one column

I am attempting to transform <div></div> <div></div> <div></div> Three consecutive divs into the following format. Div 1 is red, div 2 is green, and div 3 is blue. I have achieved this using floats, like so: .div1 { ...

submit the JSON formatted data to the server

I am attempting to extract data from a form and transmit it to a remote server: Below is the code snippet: <html> <head> <script src="http://code.jquery.com/jquery-latest.min.js"></script> </head> ...