Adding a pair of labelled angled columns in a container that spans the full width is a breeze

I'm in pursuit of this: https://i.sstatic.net/HYbC1.jpg

What I currently possess is:

<div class="row slantrow">
    <div class="row slant-inner">
        <div class="col-md-6 slant-left">
            <p>text</p>
        </div>
        <div class="col-md-6 slant-right">
            <p>text in another div</p>
        </div>
    </div>
</div>

Along with some CSS:

.slant-left {

}
.slant-right {
    background-color: antiquewhite;
}
.slantrow {
    background-color: bisque;
}
.slant-inner {
    width: 1100px;
    margin: 0 auto;
}

I am aiming to make DIV1 (60% of the width) and DIV2 (40% of the width) together fill the width of the page content.

Challenges at hand:

  1. Implementing a slanted border for DIV2
  2. Extending the background color of DIV2 beyond its parent container

What would be the best approach to achieve the desired appearance shown in the image?

Answer №1

If you're looking to achieve this effect without worrying about IE support, you can use CSS clip-path.

.slantrow {
    position: relative;
    background-color: bisque;
}
.slant-inner {
}
.slant-left {
    width: 60%;
}
.slant-right {
    width: 40%;
    /*background-color: antiquewhite;*/
}

.slant {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    /* Play with `left` here */
    /* Used -15px, as the default gutter with in BS is 30px, you can adjust this based on your setup */
    left: calc(50% - 15px);
    background-color: antiquewhite;

    /* Play with `calc()` here */
    -webkit-clip-path: polygon(0% 0%, 100% 0%, 100% 100%, calc(0% + 15px) 100%);
    clip-path: polygon(0% 0%, 100% 0%, 100% 100%, calc(0% + 15px) 100%);
}
<div class="slantrow">
    <div class="slant"></div>

    <div class="container slant-inner">
        <div class="row">
            <div class="col-6 slant-left">
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ipsum lectus, lacinia sed facilisis vel, euismod at quam. Pellentesque in urna dui. Duis ut elit id erat interdum tempor. Nam at lectus sit amet dolor interdum cursus a non enim.</p>
            </div>

            <div class="col-6 slant-right">
                <p>Morbi et pretium ex. Ut eros sapien, tincidunt et tincidunt eu, semper in libero. Nunc luctus ornare massa ut porta.</p>
            </div>
        </div>
    </div>
</div>


<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>

Answer №2

Insert an additional div called slant-middle between slant-left and slant-right, ensuring it has the same background color as slant-left. Rotate this div to a 45-degree angle.

transform: rotateZ(45deg);
-ms-transform: rotateZ(45deg);
-moz-transform: rotateZ(45deg);
-webkit-transform: rotateZ(45deg);
-o-transform: rotateZ(45deg);

Answer №3

To achieve this desired outcome, a pseudo-element can be utilized. Refer to the code snippet below (view full page for a more precise representation):

* { box-sizing: border-box; }

.slantrow {
  background-color: bisque;
}

.slant-inner {
  display: flex;
  width: 1100px;
  margin: 0 auto;
}

.slant-inner p { position: relative; } /* To prevent text overlap with slanted box */

.slant-left {
  width: 60%;
  padding-right: 5%;
}
.slant-right {
  position: relative;
  width: 40%;
  padding-left: 5%;
  background-color: antiquewhite;
}
.slant-right::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: inherit;
  transform-origin: bottom left;
  transform: skewX(10deg);
}
<div class="row slantrow">
    <div class="row slant-inner">
        <div class="col-md-6 slant-left">
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean et augue at ipsum semper auctor a ut ante. Vivamus lacinia mollis semper. Aliquam fringilla eros at tortor semper, eget finibus urna tincidunt. Nulla mollis vestibulum elit vitae element...nibh laoreet, egestas velit id, ultrices arcu. Curabitur eget iaculis orci. </p>
        </div>
        <div class="col-md-6 slant-right">
            <p>Aenean varius sollicitudin nulla. Proin in nisi urna. Aliquam ullamcorper dui vitae augue fringilla cursus vel finibus justo. Nullam tortor urna, rutrum et vulputate congue, consequat vitae nunc. Integer sit amet nibh blandit, venenatis velit u...mus quis leo eu quam sagittis egestas vel at eros. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
        </div>
    </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

How can we parse the returned 'data' as HTML in JavaScript/jQuery to select more elements?

After receiving data from a webservice, it turns out that the data is just raw HTML without any XML headers or tags around it, but simply a piece of HTML code. <div class="Workorders"> <div id="woo_9142" class="Workorder"> <span ...

Is It Possible to Use Separate Stylesheets for Different Web Browsers?

I have been trying to implement a JavaScript code that loads a specific stylesheet based on the user's browser. However, it seems like the code is not functioning correctly as none of the stylesheets are being displayed. I have meticulously reviewed t ...

Ensure that the HTML input element only accepts positive values, including decimal numbers

I need to build an input field that only accepts positive numbers, including decimal values. Leading zeros are not allowed, and users should not be able to paste invalid values like -14.5 into the field. Here is my current implementation: <input type= ...

Enhance the aesthetics of material-ui tooltips by utilizing @emotion/styled

Can material-ui tooltips be customized using the styled function from @emotion/styled? import { Tooltip } from '@material-ui/core'; import styled from '@emotion/styled'; const MyTooltip = styled(Tooltip)` // customize the tooltip ...

Is it possible to modify the underline color while using the transition property in CSS?

One of the challenges on my website is customizing the navigation bar to resemble the BBC navigation bar. I want to change the border bottom/underline color using transition elements. Can anyone provide guidance on modifying the code to achieve this look? ...

Problem occurs when tab links vanish after clicking on another part of the website

Exploring the world of Javascript as a newcomer has been quite an adventure, but I've encountered a hurdle with tab links on my website. Everything seems to be working fine – the links cycle through and display the correct content. However, when it ...

The Jqueryui image link is not displaying the image despite no error being reported

Can anyone help me figure out what I'm missing? I'm currently working with ASP.NET MVC 5 and have downloaded the JqueryUI combined via Nuget package. Despite no error references for css/js files, the close button is still not showing in the ima ...

Difficulties encountered while attempting to modify a class using Javascript

Recently, I've encountered an issue with my JavaScript where I am unable to keep a particular element's class changed. Despite attempting to change the class to "overlist", it only stays that way briefly before switching back to its original stat ...

Having trouble with the filtering feature in Material UI Datagrid

I'm currently using Material UI Data Grid to display a table on my website. The grid has an additional filter for each column, but when I click on the filter, it hides behind my Bootstrap Modal. Is there a way to bring it to the front? https://i.stac ...

Alert Box Displays Variable Name Instead of Label Name in Form Validation - MM_validateForm()

Looking at the screenshot, you can see variable names such as "email_address", "email_message" and "email_subject". I would like these to be displayed as "Email", "Message" and "Subject" instead. The validation in this form is done using MM_validateForm() ...

Is it possible to make one <td> tag bold in a table if the <tr> contains two <td> tags?

I need to make the first td tag bold and apply this style to the entire table. <table> <tr> <td><strong>Cell A</strong></td> <td>Cell B</td> </tr> </table> ...

Creating a well-aligned form using Material-UI

Exploring Material-UI for the first time! How can a form be built where certain fields are arranged horizontally, others stacked vertically, and all aligned perfectly both vertically and horizontally? Check out this example image: https://i.sstatic.net/5R ...

What is the best way to dynamically adjust the size of a Google map on my website automatically

I need assistance with placing a Google map on a webpage along with textboxes in the div below it: <div id="map_area"> <div id="map_canvas"></div> </div> <div id="date_range"> <input type="text" id= ...

"Creating Eye-Catching CSS Animation Effects with Dynamic Initial States

I am looking to understand how I can seamlessly transition from a hover-triggered animation to an exit-hover animation, regardless of where the hover animation is in progress. Currently, if I exit hover too quickly, the animation jumps back to its starting ...

Tips for displaying only one image when clicked and hiding other divs:

Currently tackling a project that involves JavaScript and I've hit a roadblock. Before you dive into the text, take a look at the image. Check out the picture here. I have successfully created a slider, but now I want to implement a feature where cli ...

OutOfMemoryError caused by Bitmap

I'm experiencing an issue with this error. I created a favicon parser from URLs using the following code: public class FavIconParser { public static String extractUrl(String url) { StringBuffer sb = new StringBuffer(); Pattern p = Pattern.co ...

Adjusting the image placement within a modal window (using bootstrap 3)

Behold, an example modal: <!-- Large Modal --> <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"> <div class="modal-dialog modal-lg"> <div class="modal-content"> ...

Angular.js, require.js, and jQuery Plugin all combined to create a uniquely customized directive

As a newcomer to Angular and Require, I am seeking assistance with the following code snippet. Despite successfully integrating Angular and Require, I am facing an issue where the bootstrap-switch element fails to initialize: define(['myapp.ui/module ...

Best practices for personalizing components installed with Bower

After using Bower to install a package such as bootstrap-sass-official, it is stored in the bower_components directory. Packages like Bootstrap allow for customization by making changes to the file bower_components/assets/stylesheets/_bootstrap.scss. You c ...

Loading and refreshing iframe content in real-time using JQuery on change() and keyup() events

I have been tackling a unique challenge with my custom CMS in Drupal for a couple of weeks now. I am facing an issue where I need to dynamically load a URL by extracting the node ID from the target Drupal page and appending it to the base URL of the websit ...