Stylish slanted divs achieved using Bootstrap 4

I'm currently in the process of constructing a block with 6 slanted divs using Bootstrap. Take a look at the image provided below:

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

After attempting to use rows and columns, I noticed that they weren't aligning correctly with each other as shown in the following image:

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

Although I also attempted the solution suggested here, I found that it only worked for a single row layout. When trying to create a 2-row layout like the one depicted in the image above, the alignment breaks. Could someone please demonstrate how I can achieve the desired layout?

.section-3 .part1 {
  clip-path: polygon(0 1%, 100% 0%, 93% 100%, 0 100%);
}

.section-3 .part2 {
  border: 2px solid black;
  transform: skew(-20deg);
}

    ... (additional CSS code omitted for brevity)

<section> - HTML code has been slightly modified  
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

<div class="row section-3 text-white animated fadeInLeftBig">
    <div class="col-md-4 pt-3 pb-3 mb-3 bg-black part1">
        <h3 class="text-white font-italic"><strong>PEOPLE</strong></h3>
    </div>
    <div class="col-md-4 pt-3 pb-3 mb-3 part2">
        <h3 class="text-black"><strong>PROMISE</strong></h3>
    </div>
    <div class="col-md-4 pt-3 pb-3 mb-3 pl-xl-5 pl-md-5 pl-xs-1 bg-blue part3">
        <h3 class="text-white font-italic"><strong>PROGRESS</strong></h3>
    </div>
</div>
<div class="row section-4 text-white animated fadeInRightBig">
    <div class="col-md-4 mb-3 bg-black part1 pr-md-5">
        <h3 class="text-white pt-5 pt-md-3 pl-xl-5 pl-3"><strong>We put our<br> people first</strong></h3>
        <p class="pl-xl-5 pl-3">Learn how we value our people<br>Become part of our family</p>
    </div>
    <div class="col-md-4 mb-3 part2"></div>
    <div class="col-md-4 mb-3 part3"></div>
</div>

Answer №1

To achieve the desired layout, you need to structure your content in one row with three columns, each containing a title and an image:

.title {
  background: #f2f2f2;
}

.img {
  min-height: 300px;
  background: center/cover no-repeat;
}

.col:first-child {
  clip-path: polygon(0 0, calc(100% - 15px) 0, calc(100% - 10vw) 100%, 0 100%);
  margin-right: -5vw;
}

.col:nth-child(2) {
  clip-path: polygon(10vw 0, calc(100% - 15px) 0, calc(100% - 10vw) 100%, 15px 100%);
  margin: 0 -5vw;
}

.col:last-child {
  clip-path: polygon(10vw 0, 100% 0, 100% 100%, 15px 100%);
  margin-left: -5vw;
}

/* Adjust text alignment */
.col:nth-child(2) > .title,
.col:last-child > .title{
  padding-left: calc(10vw - 15px)!important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">

<div class="container-fluid">
  <div class="row text-center">
    <div class="col">
      <div class="title p-3">Title 1</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1012/800/800)"></div>
    </div>
    <div class="col">
      <div class="title p-3">Title 2</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1015/800/800)"></div>
    </div>
    <div class="col">
      <div class="title p-3">Title 3</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1016/800/800)"></div>
    </div>
  </div>
</div>

For more flexibility, you can utilize a CSS variable to adjust the sizing of elements dynamically:

:root {
  --s:10vw;
}

.title {
  background: #f2f2f2;
}

.img {
  min-height: 200px;
  background: center/cover no-repeat;
}

.col:first-child {
  clip-path: polygon(0 0, calc(100% - 15px) 0, calc(100% - var(--s)) 100%, 0 100%);
  margin-right: calc(-1*var(--s)/2);
}

.col:nth-child(2) {
  clip-path: polygon(var(--s) 0, calc(100% - 15px) 0, calc(100% - var(--s)) 100%, 15px 100%);
  margin: 0 calc(-1*var(--s)/2);
}

.col:last-child {
  clip-path: polygon(var(--s) 0, 100% 0, 100% 100%, 15px 100%);
  margin-left: calc(-1*var(--s)/2);
}

/* Adjust text alignment */
.col:nth-child(2) > .title,
.col:last-child > .title{
  padding-left: calc(var(--s) - 15px)!important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">

<div class="container-fluid">
  <div class="row text-center">
    <div class="col">
      <div class="title p-3">Title 1</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1012/800/800)"></div>
    </div>
    <div class="col">
      <div class="title p-3">Title 2</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1015/800/800)"></div>
    </div>
    <div class="col">
      <div class="title p-3">Title 3</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1016/800/800)"></div>
    </div>
  </div>
</div>

<div class="container-fluid mt-2" style="--s:100px;">
  <div class="row text-center">
    <div class="col">
      <div class="title p-3">Title 1</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1012/800/800)"></div>
    </div>
    <div class="col">
      <div class="title p-3">Title 2</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1015/800/800)"></div>
    </div>
    <div class="col">
      <div class="title p-3">Title 3</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1016/800/800)"></div>
    </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

Challenges with right-to-left alignment in Bootstrap 4 input groups

Recently, I was tasked with making a bootstrap v4 page RTL for a project. After adding the dir="rtl" attribute to the code, I noticed that the styling of the input-group element got all messed up: <link href="https://v4-alpha.getbootstrap.com/dist/c ...

Experimenting with HTML and CSS to enhance email presentation

I am currently developing a Django application that requires sending out Emails with HTML templates. These email templates include images and dynamic variables from the Django context. However, each time I make changes to the inline CSS or HTML, I have t ...

Modifying webpage code

I am looking to develop a system where I can edit various elements such as the navbar, paragraphs, and images directly from a web page. I understand that this can be achieved with JavaScript, but I am facing the issue of my customizations reverting to defa ...

Finding your current location and address using HTML5 geolocation

My web application utilizes HTML5 geolocation to obtain latitude and longitude coordinates. I am looking for a way to convert these coordinates into actual addresses whenever possible. Once that is done, I need to save the address information into a MySQ ...

"Styling a play button on top of an image using CSS

Can someone please assist me in properly displaying a play button over a thumbnail using CSS in my WordPress site? I have tried various methods without success. Any guidance on where I may be going wrong would be greatly appreciated. .post-thumbnail-sid ...

Exploring the world of digital audio files and understanding the distinction between 'file:/// and '

I'm experiencing an issue with playing MP3 and MP4 files in Firefox and Internet Explorer. Can someone explain the difference between running a page by double-clicking on it (file:///...) compared to using IIS (http://...)? <object data="../../Med ...

An issue with excess whitespace appearing below the footer while adjusting the size of the webpage

I have a database table on my website that I am styling with the help of bootstrap. Check out this screenshot for the issue: https://i.sstatic.net/CUkjz.jpg For the HTML code, you can view it here: And for the relevant CSS, click on this link: I used pa ...

Tips for sorting search results while utilizing typeahead feature from ngx-bootstrap?

In my typeahead setup, I have a customTemplate with three fields: ({{model.number}}-{{model.city}}-{{model.state}}) While using the number as the typeaheadOptionField, I've noticed the presence of a typeaheadGroupField which I utilized on the number ...

Reactjs encountering issues loading css file

Currently, I am working on a project in Reactjs with Nextjs. To add CSS to my project, I have stored my CSS files in the 'styles' folder. In order to include them, I created a file called '_document.js' and implemented the following cod ...

A guide to spinning an image in every direction with CSS

I'm working on rotating an image in all directions using CSS and Vue.js. To demonstrate this, I have created a CodePen with the necessary code below. <div id="app"> <v-app id="inspire"> <div class="text-xs-center image-rotation" ...

"Utilizing Box elements, implementing linear gradients, styling with CSS, and

Currently, I am working on a project that involves using react JS and I am trying to find a solution for implementing linear gradient in multiple boxes. Specifically, I want to achieve the effect of having three identical boxes lined up next to each other. ...

Combination of Laravel with Bootstrap Icons

To enhance my Laravel 8 project, I integrated bootstrap-icons using the npm command npm i bootstrap-icons Prior to this, I had executed npm install and npm run dev to activate Laravel/UI. However, when attempting to add a basic icon with <i class = &q ...

Delivering a Captivating JavaScript Pop-Up upon Page Loading

I have a simple pop up window (with no content) that triggers with the 'onclick' event. How can I modify the code below to make the popup appear automatically when the page loads? <head> <title>Popup Display</title> < ...

What is the best method for removing quotation marks from HTML generated by Django?

I need to show a hyperlink in a form based on information retrieved from a database. Since Django doesn't seem to have built-in support for this feature, I am attempting to create the HTML code manually. Within the model form, I am customizing the in ...

What is the best way to send props to a styled component without needing to convert them to transient props beforehand

Recently, I designed a custom Text component that accepts several props. These props are then forwarded to the styled component where specific styles are applied. However, I am facing an issue where I do not want these props to be passed down to the DOM, b ...

how can you make keyframe animation pause at the last stage?

Here is an example of utilizing CSS animations: .show-left-menu { -webkit-animation-name: leftSidebarAni; -webkit-animation-duration: .25s; -webkit-animation-timing-function: ease-out; -webkit-animation-iteration-count: 1; } @-webkit-keyframes l ...

AngularJS Gallery Showcase

Trying to showcase a collection of videos in a modal using angular.js, I decided to implement the solution from . However, I encountered difficulty in integrating my scope variables into the "html5gallery" class. <div class="html5gallery" data-skin="ho ...

Tips to successfully utilize addEventListener on a submit action

Having issues getting this to work on submit, it functions properly when using document.getElementById("gets").addEventListener("click", b_button); but does not work when I try document.getElementById("gets").addEventListener ...

Stylized with different images scattered across the browser window

Is there a way to ensure that all my randomly positioned images stay within the bounds of their 100% wrap without being cut off? Currently, some images are getting cut off due to the overflow: hidden setting. Also, is it possible to prevent the images from ...

Preserve line breaks within HTML text

Utilizing the powerful combination of Angular 5 and Firebase, I have successfully implemented a feature to store and retrieve movie review information. However, an interesting issue arises when it comes to line breaks in the reviews. While creating and edi ...