Creating a triangular shape using CSS positioned at the edge of an element

Looking for help to style the bottom border of my code. Here's what I have so far:

I want it to look like the image below:

Can I achieve this using pseudo-elements or do I need to add another element in the HTML?

Thank you in advance.

body {
  background-color: #f3ece5;
}

.categories-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 25px;
    padding: 40px;
}

.categories-grid .single-category {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      padding: 20px 0;
      border: 1px solid #e2d2c2;
      background-color: white;
}
<section class="categories">
  <div class="container">
    <div class="categories-grid">
      <div class="single-category">
        <img src="https://via.placeholder.com/200x140" alt="image" />
        <h3>Title</h3>
        <div class="link">
          <a href="#">somewhere</a>
        </div>
      </div>
        
           <div class="single-category">
          <img src="https://via.placeholder.com/200x140" alt="image" />
          <h3>Title</h3>
          <div class="link">
            <a href="#">somewhere</a>
          </div>
        </div>
        
           <div class="single-category">
          <img src="https://via.placeholder.com/200x140" alt="image" />
          <h3>Title</h3>
          <div class="link">
            <a href="#">somewhere</a>
          </div>
        </div>
      </div>
    </div>
</section>

Answer №1

Using a combination of pseudo elements and skew transformation can create a unique element shape. Each pseudo element contributes to half of the overall design.

body {
  background-color: #f3ece5;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 25px;
  padding: 40px;
}

.categories-grid .single-category {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 20px 0;
  border-top: 1px solid #e2d2c2;
  position: relative;
  z-index: 0;
  overflow:hidden;
}
.categories-grid .single-category:before,
.categories-grid .single-category:after {
  content:"";
  position: absolute;
  z-index: -1;
  width: 50%;
  height: 100%;
  background: #fff;
  border: solid #e2d2c2;
}
.categories-grid .single-category:before {
  top:0;
  left:0;
  transform: skewY(8deg);
  transform-origin: right;
  border-width: 0 0 1px 1px;
}
.categories-grid .single-category:after {
  top:0;
  right:0;
  transform: skewY(-8deg);
  transform-origin: left;
  border-width: 0 1px 1px 0;
}
<section class="categories">
  <div class="container">
    <div class="categories-grid">
      <div class="single-category">
        <img src="https://via.placeholder.com/200x140" alt="image" />
        <h3>Title</h3>
        <div class="link">
          <a href="#">somewhere</a>
        </div>
      </div>

      <div class="single-category">
        <img src="https://via.placeholder.com/200x140" alt="image" />
        <h3>Title</h3>
        <div class="link">
          <a href="#">somewhere</a>
        </div>
      </div>

      <div class="single-category">
        <img src="https://via.placeholder.com/200x140" alt="image" />
        <h3>Title</h3>
        <div class="link">
          <a href="#">somewhere</a>
        </div>
      </div>
    </div>
  </div>
</section>

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

JQuery-enabled button allows for the deletion of a dynamically generated list item

In my HTML file, there exists an ordered list: <ol id ="list"> </ol> As the user interacts with the page using JQuery and JavaScript, items are dynamically added to this list. Here's how it's done: $(function (){ $("#click-me") ...

The 600 pixel wide page is not completely filling the 640 pixel width screen on a mobile device

Currently, I am conducting a test on a webpage using an iPhone 5s with a screen resolution of 1136 x 640 pixels. The meta tag is set as follows: <meta name="viewport" content="user-scalable=yes, initial-scale=1, width=device-width, shrink-to-fit=no"&g ...

Is IE8 compatible with HTML5 and CSS3?

My client has requested their website to be developed using HTML5 and CSS3. However, it has come to my attention that IE6 and IE7 do not have full support for HTML5 and CSS3. The client claims that IE8 does support these technologies, but I need more inf ...

Struggling to display the array after adding a new item with the push method

Seeking assistance in JavaScript as a newcomer. I have written some code to print an array once a new item is added, but unfortunately, it's not displaying the array. I am puzzled as there are no errors showing up in the console either. In my code, I ...

"Issues with Angular ng-show Functionality on Internet Explorer Versions 7 and

I'm currently working on a feature where I need to show or hide two divs conditionally using ng-show based on the completion of an AJAX call. The layout for this includes: <div id="div1" ng-show="!loadingData"> <!--Some markup here--> ...

How do I use jQuery to animate a height increase where the added height is applied to the top of the element?

I am facing a simple issue that I need help resolving. The problem involves hidden content that, once expanded, needs to have a height of 99px. When collapsed, the container holding this content section#newsletter is set to be 65px in height. If you want ...

Issues with stationary navigation bars

Having trouble with the fixed navigation bar, as it appears slightly lower on section links. I want the navigation bar to be at the top so that the title text in sections is clearly visible. I attempted to add margin-top to the section, but the gaps were t ...

Unlock the power of Component level CSS in NextJS with this simple guide!

I don't have much experience with CSS, as I rarely write it these days due to the popularity of libraries like MUI. However, I recently found myself in a tricky situation where I needed to rewrite this example Emabla carousel in typescript and NextJS. ...

Achieving alignment between a button and input field using Bootstrap CSS

Struggling to align my buttons next to the inputs in my project, particularly due to my inexperience with bootstrap CSS and CSS in general. Could someone please point me in the right direction? Link to the issue Unfortunately, my Search and New buttons a ...

Customize Bootstrap Navbar to Enable Horizontal Scrolling Specifically for Dropdown Buttons

Specific requirements: - Only buttons should be horizontally scrollable - Dropdown of buttons should appear just below the button without shifting the paragraph below Things I have attempted: - Tried using overflow:hidden/auto, overflow-x:auto, and pos ...

Add an exciting new element to the array within the DOM using knockout.js

Is there a way to make the font color change to red and then back to white when a new item is added to a play by play array using knockout? I know how to achieve this effect on a single property with the provided binding, but I'm unsure of how to do i ...

An abundant array of options spread across numerous dropdown menus

I have been tasked by a client to do something new that I haven't done before, so I am seeking the best approach. The project involves creating a form with three dropdown menus where users can select from thousands of options. For instance: Users mu ...

Tips for aligning a Bootstrap container in the middle of the viewport vertically

I'm struggling to center a Bootstrap container vertically in the viewport. You can view my code at http://www.bootply.com/C8vhHTifcE All of my attempts at centering have been unsuccessful. Does anyone have a solution? Just to clarify: I want the co ...

Tips for updating the content of a DIV element on a separate page

One question that often arises is how to change the content of a div element on a different page within a website. While it is common to use Ajax to dynamically update div content within the same page by fetching data from an external .html file, the proce ...

Is it wise to use the<sup>attribute for mandatory form fields?

Would it be wise to utilize the <sup> tag instead of using margin-top: -xnumberofpx for indicating required fields in a form? <label for="address1" required>Address line 1<sup><img src="/src/images/requiredAsterix.png" width="10" heig ...

Using a video as a background in HTML

My code has an issue where I have set overflow: hidden in the CSS but the video is still not displaying below the text as intended. The relevant CSS snippets are: fullscreen-bg { top: 0; right: 0; bottom: 0; left: 0; overflow:hidden ...

At what browser width does Bootstrap's container no longer display a border?

I'm in the process of creating a flexible website design. https://i.sstatic.net/68qW2.png Everything seems to be going well so far. Here's what I have: <div class="container"> <div class="products-block"> <h2>Prod ...

HTML embedded content is not appearing on the React webpage

I'm attempting to incorporate GoFundMe donation buttons into a React page, but unfortunately, they aren't displaying on the screen. const Donation = () => { return ( <div> <div className="gfm-embed" d ...

Implementing manual updates for the bootstrap color picker

I have integrated a color picker from Bootstrap into my project. You can find the color picker here: To change the background color of an element on my page, I am using the following code: <input type="text" id="mypicker" name="mypicker" value="" cla ...

Adjust the alignment of text on both ends of the HTML5 canvas

Is there an easier way to align text on both sides of a canvas element besides using CSS? The link below might provide some insight: https://github.com/nnnick/Chart.js/issues/114#issuecomment-18564527 I'm considering incorporating the text into the d ...