Responsive Alignment of Slanted Edges using CSS

I have been working on creating a responsive diagonal layout with slanted shapes (refer to the image attached). However, I'm facing a challenge with aligning the edges smoothly at different screen sizes, especially when the rows grow and the screen resizes.

Is there a way to vertically align the top edge of each slanted shape with the bottom edge of the one above it?

Currently, my solution involves adjusting the left position of the ::before pseudo-element on the skewed shapes. But I am seeking a more efficient approach to achieve this responsiveness as the layout evolves with varying screen sizes.

https://i.stack.imgur.com/pSluF.png

.slant::before {
  background-color: lightblue;
}
.lr .right-content,
.rr .left-content {
  background-color: green;
}
.lr .slant,
.rr .slant {
  position: relative;
}
.lr .slant::before,
.rr .slant::before {
  content: '';
  transform-origin: 100% 0%;
  position: absolute;
  top: 0;
  bottom: 0;
}
.lr .slant::before {
  transform: skewX(-10deg);
  left: -100vw;
  right: 0;
}
.rr .slant::before {
  transform: skewx(10deg);
  left: 0;
  right: -100vw;
}
<div class="container">
  <div class="row lr one">
    <div class="col-xs-5 left-content slant">
      <h1>Title</h1>
    </div>
    <div class="col-xs-7 right-content">
    </div>
  </div>

  <div class="row rr card two">
    <div class="col-xs-5 left-content">
    </div>
    <div class="col-xs-7 right-content slant">
      <p>Lorem Ipsum is simply dummy...</p>
      <p>Lorem Ipsum is simply dummy...</p>
      <p>Lorem Ipsum is simply dummy...</p>
    </div>
  </div>
  ...
</div>

Answer №1

Here's a cool trick with the clip-path property:

.panel {
  position:relative;
  background:lightblue;
  height:50px;
  margin:5px;
}
.panel::before {
  content:"";
  position:absolute;
  top:0;
  bottom:0;
  width:50%;
  background:green;
}
.panel.left::before {
  left:0;
  clip-path:polygon(0 0,100% 0, calc(100% - 30px) 100%,0 100%);
}
.panel.right::before {
  right:0;
  clip-path:polygon(0 0,100% 0, 100% 100%,30px 100%);
}

.panel.left.bottom::before,
.panel.right.bottom::before{
  transform:scaleY(-1);
}
<div class="panel right bottom"></div>
<div class="panel left" style="height:100px"></div>
<div class="panel left bottom"></div>
<div class="panel right" style="height:200px"></div>
<div class="panel right bottom" style="height:100px"></div>
<div class="panel left" style="height:100px"></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

insert data into modal's interface

I'm encountering an issue with my code, where the modal is not displaying the values inside the brackets as if they were not bound correctly. Everything else in the ng-repeat seems to be working fine, but for some reason the values are not being displ ...

Bring the URL back to its original state upon refreshing the page

A form was created using a combination of HTML and PHP on my website. This specific form takes a number as input, adds 2 to that number, and then displays the result. For instance, if the user enters the number 5 and clicks the submit button, the page wil ...

Evaluating the use of promise in Angular using Jasmine testing

I'm currently troubleshooting whether a method with a promise is being properly called Below is the snippet of my controller code: app.controller('StoresListController', function ($scope, StoresService) { $scope.getStores = function ( ...

The grid is evenly populated with icons

Is it possible to evenly distribute the icons by only using CSS? I'm aiming to achieve a result similar to this (unfortunately, I can't post images due to my lack of reputation). You can find an example solution that uses JavaScript here: _htt ...

Limit text to two lines inside a cell in a table

Apologies for not providing any evidence of my own efforts. I'm looking to wrap text in a table cell, but limit it to just 2 lines. Expanding the width is not possible. Any suggestions on how to achieve this? ...

the failure of the second function to execute

Struggling with a particular issue. Two functions have been created as shown below: function limit_char_normal(textid, limit, infodiv){ var text = $('#'+textid).val(); var textlength = text.length; if (textlength > limit) { ...

Breaking down objects or arrays to extract specific values in React components

Some articles recommend using ES6 destructuring for React props & state as a best practice. For example: const { showModal, hideModal } = this.props; While I understand the benefits of cleaner code, I recently discussed with another developer who suggest ...

Automatically bundle and release an NPM package using the libnpm library

My goal is to automate publishing to NPM within my CI/build system. I came across libnpmpublish, which appears to be the right tool for the job. However, it clearly states that it does not package code into a tarball, even though the publish API requires a ...

How can I swap a string for a symbol in JavaScript?

Is there a way to convert the text @abc some text here to <a href="some_url">@abc</a> some text here using JavaScript? Are there any libraries that can help with this task? ...

Using async/await in combination with Vuex and Feathers

Please review my code below. I am attempting to integrate Async Await into vuex. While everything is functioning properly, I would like to call another action after this one using async await. However, the expected result is not being achieved as the conso ...

How can you position text to the right of an image using CSS?

Trying to right-align text next to an image; CSS .p1 { position: absolute; width: 100px; height: 50px; top: 40%; left: 70%; } HTML <img src=../images/diagram1.png alt="Diagram"/> <span class="p1">This is a tes ...

Bootstrap progress bar loading does not function properly

I have a progress bar on my page with three parts: progress-bar-success, progress-bar-warning, and progress-bar-danger. I would like each part of the progress bar to complete sequentially, starting with progress-bar-success, then progress-bar-warning, and ...

Exploring the possibilities of integrating JavaScript with Flash technology

Currently, there is a simple Flash project in development that connects to an RTMP server and streams video and audio from a webcam. The project allows users to create a stream with a specific name. This project also features an input for entering a strea ...

Calendar Complete If a month has no scheduled events, the calendar will seamlessly move on to the next month

Is it possible to set up full calendar so that it automatically advances to the next month if there are no events scheduled? For example, if there are no events in June or all events have already taken place, can the calendar automatically move on to July ...

Learning the process of utilizing Json in Flot to create visually appealing graphs

I'm currently utilizing the Flot Graph Api to showcase bar charts and line charts on my client-side PHP environment. I am attempting to pass Json data to plot the graph as outlined in their examples. This is how I structure the Json data: [{"label": ...

Here is a guide on how to develop a PHP function that interacts with a textarea to display text in the specified color by using syntax like [color:red]

Is it possible to code a PHP function that can work alongside a textarea to display text in the specified color by using a syntax like [color:red]? This function operates in a similar manner to Facebook's @[profile_id:0] feature. ...

Overridden CSS rules

Having a slight CSS dilemma. Within my webpage's html, I have the following structure: <div class='box-div'> <div>Entry 1</div> <div class='hide'>Entry 2</div> </div> Here is my associated ...

Is it advisable to incorporate the <main> element in my code?

While browsing through w3schools, I came across the <main> element. However, according to caniuse.com, this element is not supported by IE, Opera Mini, and the UC Browser for Android. Should I opt for using a <main> element instead or stick wi ...

Unveiling Insights from a JSON File: Data Extraction

I have a JSON file named pio2.json that contains the following data: { "controles":[{ "chart":[{ "type":"columns", "title":"Pollitos" }], "datos":[{"key":"Math","value":98}, {"key":"Physics" ...

What is the integration process of using Font Awesome with React?

After installing react-create-app using npm, I also added react-fontawesome. Now, I'm wondering how to include the css styles of fontawesome in my project? Here is a glimpse of my work space: https://i.stack.imgur.com/pM1g1.png ...