Is there a way to use CSS to clip a side of a DIV element?

Imagine a scenario where there is a parent div named "clip" and a child div named "page." These two divs have specific dimensions, as shown below:

<div id="clip"> 
  <div id="page"> 
     <!-- Content/Images here -->
  </div>
</div>

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

The height and width of these two divs are as follows:

#clip {
  height: 1000px;
  width: 1414px;
}

#page {
  height: 1000px;
  width: 707px; 
}

Now, the challenge at hand is to skew a side off from the child div at an angle ΓΈ and clip the right side of the div, creating a visual effect like this:

https://i.sstatic.net/3MkqP.png

Is it possible to achieve this using solely CSS?

Note that we cannot use the triangular border hack or skew the content inside the #page child div. We are looking for a clean CSS solution without any hacks. Can CSS3 transformations help us achieve this effect?

@ksav has suggested a solution that involves obscuring part of the div with a pseudo :before element positioned absolutely. However, this approach does not fully meet our requirements as we aim to make the clipped part of div#page completely disappear, resulting in a design similar to this:

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

Answer β„–1

To achieve the desired effect, you can utilize -webkit-clip-path property.

#clip {
  height: 1000px;
  width: 1414px;
  background-color: yellow;
}

#page {
  height: 1000px;
  width: 707px; 
  background-color: blue;
  color: white;
  -webkit-clip-path: polygon(0 0, 40% 0, 29% 100%, 0% 100%);
} 

For a live demonstration, refer to this example: https://codepen.io/rollinglex/pen/ZMNvjY

If you're looking for more resources, check out this website:

Additionally, for insights on using JavaScript and CSS together, you may find this article helpful:

Answer β„–2

.background-wrap {
  background: grey;
  position: relative;
 height: 1000px;
  width: 707px; 
}

.background-wrap:before {
  background: rgba(255, 255, 255, 0.8);
  position: absolute;
  height: 100%;
  width: 110%;
  transform: skewX(-5deg) translateX(10%);
  transform-origin: bottom left;
  content:'';
}
<div class="background-wrap">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras imperdiet congue aliquam. Etiam efficitur lectus id nulla iaculis dapibus. Phasellus nec nisl bibendum, hendrerit diam at, consequat est. In posuere lorem eget felis venenatis elementum.
    Ut vestibulum a nulla commodo pharetra. Cras accumsan dui a libero faucibus rutrum. Integer sed nunc accumsan, convallis lectus venenatis, iaculis arcu. Pellentesque tincidunt purus eu pulvinar tempus. Nam aliquet orci vel sapien condimentum pharetra.
    In rhoncus vehicula metus, vitae euismod mauris consequat sit amet. Praesent suscipit quam libero, eget semper neque aliquet faucibus.</p>
</div>

View on Codepen

Answer β„–3

div{
  width:50%;
  height:100%;
  position: absolute;
  border: 1px solid black;
}
#parent{
  background: #fff333;
}
#child{
  background: #aaaccc;
  left: 30%;
  transform: skewX(-8deg);
}
<div id="parent">

</div>
<div id="child">
  
</div>

Yes, it is definitely possible and below is a basic method to achieve it. While not the most optimized solution, it does get the job done effectively.

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

Modifying iframe src using click event from a separate component in Angular 10

I am looking to dynamically update the src attribute of an iframe when the menu bar is clicked. The menu bar resides in a separate component and includes a dropdown menu for changing languages. Depending on which language is selected, I want to update the ...

Mastering Fluent UI Web: Adjusting the border radius of a TextField component

I am in the process of creating a custom user input control that includes a TextField, a Dropdown, and a Button. To ensure that the TextField and Dropdown appear as a cohesive unit rather than two separate elements, I attempted to use two specific styles ...

I am having trouble navigating between my HTML files using the links

I am struggling with linking my HTML pages together. Despite anchoring the links, when I click on them in HTML format, it gives me a file not found error. I have three pages that need to be interconnected. Before testing it out, I place them all in one fo ...

Chrome does not allow the use of a CSS property for hover that has been used for animation

One issue I encountered is that when using a CSS property for animation and then also using the same property for a hover effect in Google Chrome, the hovering effect does not work properly. Below is the animation code: @keyframes fadeInUpBig { 0% { ...

Attempting to invoke setState on a Component before it has been mounted is not valid - tsx

I've searched through various threads regarding this issue, but none of them provided a solution that worked for me. Encountering the error: Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a b ...

Javascript timer that counts down using cookies for storage

Seeking assistance - I am in search of a solution to create a javascript countdown timer that utilizes cookies. I need the timer to remain consistent even when the user refreshes the page, until a specific time has elapsed. This is for an online examinat ...

Challenges with implementing speech recognition within a React component's state

I've encountered an issue with the React library react-speech-recognition. When trying to modify the newContent state within useEffect, it ends up printing as undefined. Additionally, I'm facing a similar problem when attempting to update the sta ...

Calculation for determining the fill of a DIV's remaining height

Here is what I have: <div id="modal-container"> <div id="modal-body"></div> <div id="modal-footer"></div> </div> I am currently working on a JavaScript function to adjust the height of #modal-body to fill in the re ...

Exploring the Towers of Hanoi Puzzle with Javascript

Recently, I've been working on a school project where I need to present an algorithm for solving the Towers of Hanoi puzzle. Utilizing my knowledge in HTML/CSS, I decided to visually represent the algorithm using JavaScript on a webpage. I've se ...

Having trouble with a jumpy carousel? After each transition, it seems like the image is hopping within the frame, getting smaller and then bigger

As I am still new to coding and using tools like bootstrap and Dreamweaver, I encountered an issue with a carousel on my website. Everything was working smoothly until the images started losing the bottom half when auto-scrolling or clicking to scroll righ ...

Hide the button with jQuery Ajax if the variable is deemed acceptable upon submission

I need to figure out how to hide the submit button if the email entered is the same as the one in the database from action.php. Can anyone help me with integrating this functionality into my existing code? <form onsubmit="return submitdata();"> ...

Adjust the color of the background when hovering with the cursor

I am currently working on a project with a menu of buttons that dynamically changes based on the elements in a list. For instance, if my list contains ["A", "B", "C"], then I would have a menu with 3 buttons. Here is how I display the buttons using a java ...

The URL is not being updated despite changes in document.location hash

I have created a script that toggles (show/hide) between different DIVs on the page (highlighted below in the various boxes =). However, I am facing an issue with updating the URL string when switching between different DIVs. For instance, if I navigate t ...

Storing data with ElectronJS

I am currently working on an Electron JS and React JS offline application. One of the initial steps in my launch process involves loading a large file that is over 1 GB in size and cannot be divided. This causes a delay of approximately 50-60 seconds whi ...

Why is CSS styled by jQuery not working on hidden elements?

My challenge involves applying CSS to hidden elements and revealing them when a user interacts with a radio button. The issue arises when using CSS through jQuery to dynamically set the width of these elements. Because the elements are initially set to dis ...

Locate the element within the specified parameters using [protractor]

Here's my query: element.all(by.repeater('user in users')).then(function(rows) { // looking to locate an element in rows using CSS selector, for example } UPDATE : I want to clarify that I am trying to find an element using rows[rows.len ...

Prevent regex from matching leading and trailing white spaces when validating email addresses with JavaScript

In my current setup, I utilize the following regular expression for email validation: /^[a-zA-Z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/ My attempt to validate the email is shown below: if (!event.target.value.match(/^[a-zA-Z0-9._%+-]+@[a-z0-9.-]+\. ...

Tips on creating a Django query based on user-selected options from a drop-down menu

As a newcomer in an internship role, I have been tasked with creating a website where users can select a program, location, or theme to visualize on a heatmap. To achieve this, I opted to utilize Django. However, I am facing two challenges: Firstly, my M ...

leveraging Ajax to submit a segment of the webpage

-Modified- Greetings, I am facing a situation where I need to post only the second form on a page that contains two forms. The second form has a function for validating data such as date, email, etc. My goal is to send the second form without reloading ...

Transform specific data binding values into JSON format using Knockout.js

Just dipping my toes into the world of knockoutjs, I've got this viewmodel set up: var Testing = function(){ this.Username = ko.observable(""); this.Password = ko.observable(""); this.email = ko.observable(""); } I'm tasked with ...