Create a unique trapezoidal design using only CSS styling

Imagine having two div elements beautifully displayed as shown below. Despite consulting The Shapes of CSS, the method to create the unique yellow shape featured in the image below still remains a mystery. Is it feasible to replicate this shape using techniques illustrated in the provided link?

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

Additionally, envisioning the scenario depicted in the second image below raises the question of its achievability through CSS or alternative tools. Although the curves may not be perfectly shaped, could perhaps utilizing a standard bezier curve with adjustable height produce similar results?

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

Answer №1

If you're looking to tackle the second part of the question, consider using SVG clip paths and referencing the id in the CSS. The SVG code can be found at the bottom of the HTML.

-webkit-clip-path: url(#top-path);
clip-path: url(#top-path);

More detailed information on both methods can be found here: https://css-tricks.com/clipping-masking-css/

However, it's important to note that support for clip-path is currently quite limited.

http://caniuse.com/#search=clip-path

div {
  float: left;
  height: 100px;
  width: 130px;
}
.holder {
  position: relative;
}
.top {
  width: 490px;
}
.bottom {
  width: 490px;
  position: absolute;
  left: 0;
  top: 35px;
}
.top-left {
  background-color: aquamarine;
  height: 35px;
}
.top-mid {
  background-color: aquamarine;
  width: 97px;
  -webkit-clip-path: url(#top-path);
  clip-path: url(#top-path);
}
.top-right {
  background-color: aquamarine;
  margin-top: 37px;
  height: 53px;
}
.bottom-left {
  background-color: aqua;
  height: 34px;
}
.bottom-mid {
  background-color: aqua;
  width: 97px;
  -webkit-clip-path: url(#bottom-path);
  clip-path: url(#bottom-path);
}
.bottom-right {
  background-color: aqua;
  margin-top: 55px;
  height: 45px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8>" 
  <title>SVG Clip Path Shape</title>"
</head>

<body>
  <div class="holder">
    <div class="top">
      <div class="top-left"></div>
      <div class="top-mid"></div>
      <div class="top-right"></div>
    </div>
    <div class="bottom">
      <div class="bottom-left"></div>
      <div class="bottom-mid"></div>
      <div class="bottom-right"></div>
    </div>

    <svg width="0" height="0">
      <defs>
        <clipPath id="bottom-path">
          <path d="M14.966,0.68L0,0v33.113l14.966,0.68c29.252,2.041,55.102,70.509,76.068,70.503l6.245-0.32V54.864
              .              

When it comes to the first part of the question, utilizing clip-path with specific corner coordinates separated by commas can achieve the desired effect.

-webkit-clip-path: polygon(0 0, 100% 20%, 100% 100%, 0 43%);
clip-path: polygon(0 0, 100% 20%, 100% 100%, 0 43%);

div {
  float: left;
  height: 100px;
  width: 130px;
}
.holder {
  position: relative;
}
.top {
  width: 490px;
}
.bottom {
  width: 470px;
  position: absolute;
  left: 0;
  top: 43px;
}
.top-left {
  background-color: lime;
  height: 43px;
}
.top-mid {
  background-color: lime;
  -webkit-clip-path: polygon(0 0, 100% 20%, 100% 100%, 0 43%);
  clip-path: polygon(0 0, 100% 20%, 100% 100%, 0 43%);
}
.top-right {
  background-color: lime;
  margin-top: 20px;
  height: 80px;
}
.bottom-left {
  background-color: green;
  height: 43px;
}
.bottom-mid {
  background-color: green;
  -webkit-clip-path: polygon(0 0, 100% 43%, 100% 100%, 0 43%);
  clip-path: polygon(0 0, 100% 43%, 100% 100%, 0 43%);
}
.bottom-right {
  background-color: green;
  margin-top: 43px;
  height: 57px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8>><!
  <title>CSS Shape</title>
</head>>

<body>
  <div class="holder">>
    <div class="top">>
      <div class="top-left">></div>>
      <div class="top-mid">></div>>
      <div class="top-right">></div>>
    </div>>
    <div class="bottom">>
      <div class="bottom-left">></div>>
      <div class="bottom-mid">></div>>
      <div class="bottom-right">></div>>
    </div>>
  </div>>
</body>>

</html>

Answer №2

Behold the very first shape created entirely with pure CSS. The key element needed is the perspective.

.shape {
  display: flex;
  margin: 50px;
}
.red,
.green {
  color: white;
  padding: 15px;
  box-sizing: border-box;
}
.green {
  background: green;
  position: relative;
  z-index: 2;
  width: 200px;
  height: 127px;
  margin-top: 45px;
  margin-left: -22px;
}
.red {
  width: 100px;
  background: red;
  height: 56px;
  z-index: 2;
}
.parent {
  position: relative;
  -webkit-perspective: 711px;
  perspective: 711px;
  margin-left: -30px;
  margin-top: 19px;
}
.el {
  width: 200px;
  -webkit-transform: rotateX(-27deg) rotateY(-40deg);
  transform: rotateX(-27deg) rotateY(-40deg);
  height: 65px;
  background: #FFF200;
  position: relative;
  perspective: 350px;
  -webkit-perspective: 350px;
}
.el:after {
  content: '';
  position: absolute;
  left: 0;
  top: 100%;
  border-style: solid;
  border-width: 0 200px 70px 0;
  border-color: transparent #FFF200 transparent transparent;
}
<div class="shape">
  <div class="red">Div 1</div>
  <div class="parent">
    <div class="el"></div>
  </div>
  <div class="green">Div 2</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

"Aligning a button to the right in HTML: Step-by-step

On my website, I have added a popup form for users to input their details. This form includes two buttons - one for saving the information and another for canceling the popup. I would like both buttons to be aligned on the right-hand side of the page. Each ...

The FaceBook modal is failing to appear

Attempting to implement FaceBook Login through a modal. Upon clicking the button below, the FaceBook Login Modal should appear. <li> <a href="#sign-in-dialog" class="login sign-btn" title="Sign In">Sign In</a> </li> The HTML co ...

unable to access various attributes in an angular directive

I have a particular HTML setup that effectively outlines each attribute's value through a distinct "attachment" directive. These values are located in the attrs list of said directive, which is within a modal file upload form. <p>For Testing Pu ...

Troubleshooting Django's iteration error

Hey there! I'm currently a student, so please bear with me if my code isn't perfect yet. I'm working on a project that involves creating an online webshop. The database and email system are already set up, but I'm having trouble specify ...

icon from font-awesome changes color when hovering over

My ASP.NET gridview control includes a font-awesome trash icon in the last column. I'm trying to make the icon change color to red when I hover over it, and then revert back to its default color when I move my mouse away. Here is the code for the te ...

Ways to maximize the viewport height by placing a Sidebar below a Navbar

This outlines the issue at hand: My goal is to extend the sidebar to cover the remaining height of the viewport, ensuring that the footer remains visible at all times, regardless of the varying height of the bootstrap 4 navbar. Is there a solution for ach ...

Elevate your design game by mastering CSS transformations for precise element

I am trying to center a div with a variable width using the following code: div { background: red; max-width: 400px; position: absolute; left: 50%; transform: translateX(-50%); } Check out my demo here While this code works well for centering, ...

Matching up irregular rows in div-made table

I have created a table using div elements that contain images as cell data. When an image is missing, I would like to center the remaining images in the row like this: With all images present: xxxxx xxxxx Missing images (2 in the second row): xxxxx xx ...

Putting a | in the navigation bar

Could use some assistance here as I'm struggling to add a | between 'About Us' and 'Login' in my code. Any tips on how to achieve this? I've checked other posts but can't seem to apply it correctly to my specific lines of ...

Manipulate the timing of css animations using javascript

I am currently working with a progress bar that I need to manipulate using JavaScript. The demo of the progress bar has a smooth animation, but when I try to adjust its width using jQuery $($0).css({'width': '80%'}), the animation disap ...

The hyperlink appears to be malfunctioning with an additional border surrounding it within a pop-up window

I am facing an issue with a link <a> not functioning properly with a popup dialog on . Additionally, there seems to be a border that appears around the <a> when the popup initially displays. If you click on "Leer más" for any product, you can ...

Erase periods from the text box

Is there a way to remove the dots in the right bottom corner of a textarea without disabling resizing? https://i.sstatic.net/N2zfh.jpg I have seen a solution using the css property resize:none, but I would like to keep the resizing functionality... Are ...

My HTML Won't Recognize the CSS File

Despite trying various paths and browsers, I am unable to link my CSS file to my HTML file. When inspecting the page elements and checking under resources, the CSS file does not appear. Here is a snippet of my HTML: <html> <head> <meta ...

Issue with an Angular filter for formatting a lengthy JSON string onto separate lines within an HTML document

Just starting out with coding and working in Angular, I'm trying to display JSON data from Firebase in HTML. Here's the specific call I'm using: <p>{{workout[0].box.info.training.strength.exercise[1].movement.freetext }}</p> Th ...

Issue arising from failure to check the checkbox

My ajax request is sending form data to an external PHP script and returning a result, but I'm encountering an error: Uncaught SyntaxError: Unexpected token < index.php hr.onreadystatechange This error occurs when trying to send the form without ...

``Despite setting display block, margin auto is not being adhered to as expected

Trying to position two label elements on either side of a div container has been tricky. Despite using various display properties like display: block and display: inline-block, the margins are not behaving as expected. div { color: #ffffff; ...

Choosing a box will cause a dashed rectangle to appear when the mouse is selected

Whenever I try to select an option in my select box, a dotted rectangle appears. How do I remove this feature? https://i.sstatic.net/BzsL2.png I have noticed that many others are also facing the same issue. I tried updating my CSS with some properties ba ...

Tips for displaying or concealing a div when hovering over a kendo-menu-item in Angular 8

I am seeking a way to conceal a specific div element upon hovering over a kendo-menu-item within an angular 8 project. Specifically, I would like to hide the div with the class "nav-flyout" when hovering over the kendo-menu-item labeled "what we do". Belo ...

Determine the specific line that was clicked during the execution of the PHP loop

In my PHP script, I have a while loop that fetches data from a MySQL database. This loop generates multiple unordered lists dynamically displaying the rows retrieved from the database. Each row includes a button and a hidden input containing a link as it ...

Unable to create a clickable image

My approach involves using asp:Hyperlink controls to create an image that acts as a link. Here is the sample code in both aspx and C#: <asp:HyperLink ID="mainInteractiveFileLink" runat="server"> </asp:HyperLink> C# mainInteractiveFileLink ...