Is it feasible to have several polygons at once?


I am attempting to construct a unique pyramid using CSS properties like clip-path. Despite successfully creating a triangle, my efforts to create trapezoids beneath it have not been as fruitful.

.container {
  min-width: 50%;
  max-width: 50%;
}

.triangle {
  background-color: yellow;
  clip-path: polygon(90% 100%, 50% 0%, 10% 100%);
}

.trapeze {
  background-color: blue;
  clip-path: polygon(0% 10%, 0% 90%, 0% 100%, 100% 100%);
}

div {
  min-height: 200px;
  max-height: 200px;
  border-color: black;
  border-style: solid;
}
<div class="container">
  <div class="triangle"></div>
</div>
<div class="container">
  <dic class="trapeze"> </dic>
</div>

Upon viewing the result :

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

I am working without any framework and testing in Firefox version 67

Answer №1

To achieve various shapes, use the clip-path property in combination with gradients:

.pyramid {
  width:200px;
  height:200px;
  
  -webkit-clip-path:polygon(0 100%,100% 100%, 50% 0);
  clip-path:polygon(0 100%,100% 100%, 50% 0);
  background:
    linear-gradient(to bottom,
      yellow 0    20%,
      red    20%  50%,
      blue   50% 100%);
}
<div class="pyramid">

</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

What steps can be taken to resolve the link prefetch warning in a Next.js application?

I am currently working on a Next.js application using version 13.4, and I've encountered a warning in the console: After preloading the resource at <URL>, it was not used within a few seconds of the window's load event. Please ensure that i ...

Is it possible to remove filters from image links but still apply filters to links within the same div?

Is there a way to use hue-rotate to change the colors of my text links without affecting my image links? I have tried removing the effect from images only, but haven't been successful. Any suggestions on how to achieve this? I created a JavaScript but ...

Changing CSS properties dynamically based on database values

Seeking a way to dynamically modify CSS attributes via a database field. Rather than using multiple if statements like the one below: if (@Model["font"] == "arial") //set the font to arial I'd like a cleaner solution that doesn't clutter my vie ...

It's a mystery unraveling the source of CSS margins and padding

Could someone please help me analyze this webpage? I am trying to make the center of the page white up to the navigation bar, at the bottom of the page, and horizontally up to the shadows on both sides. I'm not sure where this extra padding is coming ...

Footer Display Problem in CSS

Have you ever experienced a situation where your content is running low, and the footer ends up right under it? Instead of fixing it at the bottom using a fixed position or any other method, why not make everything below the footer match the background col ...

Stable element contained within a moving container

My content block has text that scrolls when it becomes too large. I'm trying to create an overlay div on top of this block, and I have implemented a solution in my example. I encountered issues where setting position: fixed for the overlay prevents i ...

Having trouble removing lines from Router Link? Unfortunately, using style={{'textDecoration': 'none'}} doesn't seem to be doing the trick

Does anyone know why the text decoration is not working on my link when I use text-decoration none? Any solutions or suggestions would be greatly appreciated. Thank you in advance! Navbar.js file import React,{useState} from "react"; import { mak ...

Angular2: Leveraging click events to manage CSS classes on elements

I am currently developing a web app using Angular 2. I'm facing an issue where the active element should receive an extra CSS class when clicked, but adding the ":active" CSS attribute with a custom class doesn't work as expected. The ":focus" pr ...

"Hovering over one div does not trigger the display of another div

I seem to have forgotten my CSS skills, but I am facing an issue. Here is the code snippet: <div class="footer_container"> <div class="website_logo_to_footerexpand"></div> <div class="info_cont"> <div class ...

The onClick event listener is not being recognized when using ReactDOMServer.renderToString

I am attempting to replicate the functionality of this fiddle: http://jsfiddle.net/jhudson8/135oo6f8/ (I also tried this example http://codepen.io/adamaoc/pen/wBGGQv and encountered the same issue with the onClick handler) My goal is to make the fiddle c ...

Adding a drop shadow effect to SVG elements when hovered over

I am curious if it is feasible to have a drop shadow on my SVG element, but only make it visible when hovered over (:hover). I utilized the filter tag for the SVG and this is somewhat the effect I am aiming for. From what I have read, inline :hover is no ...

Having difficulties in loading the CSS file for my real-time chat application built with Express and Socket.io

Hi everyone, I've been struggling with an issue for the past couple of days where I can't seem to load my CSS for my Express app. If anyone has a solution, I would greatly appreciate the help. Below is my server.js code: const express = requir ...

Traverse an SVG element using JavaScript

I have a beautiful star SVG that I created, and I want to use it instead of styling a span to create floating bubbles in my div. However, I'm facing some challenges in adapting my Javascript loop to incorporate the SVG for creating the bubbles, as opp ...

Error message displayed: "The timer function encountered an issue as second_input is found to be null."

var idinterval; var second_input_value = document.getElementById("Seconds"); var minute_input_value = document.getElementById("Minutes"); var second_val = second_input_value.value; var minute_val = minute_input_value.value; var total_time = parseInt(minut ...

Creating responsive modal windows in Vue and Laravel to dynamically adjust to the screen size

I am currently working with a modal window code snippet. <transition name="modal" @close="showModal = false"> <div class="modal-mask" style=" width: 90% !important;"> <div class="modal-wrapper"> < ...

When the anchor tag is clicked, I'm displaying the DIV for Customer Testimonials, however, the expansion of its height is not

One way to display customer testimonials is by using flexslider to create a horizontal scroll. The testimonials are hidden and only shown when the "view all testimonials" link is clicked, which can be seen in this JSFiddle example: Working : Demo JQuery ...

What is the proper way to utilize li.class:hover in CSS code?

When trying to apply a class to an li element during a hover event, I encountered some difficulties. Below is the code that works without the class: #leaderboard li:hover { z-index:1000; -webkit-transform: scale(3.2); -moz-transform: scale(3.2 ...

When I tried to address one issue, my CSS ended up breaking. Any suggestions on how I can resolve the header

Edit: https://i.sstatic.net/kVeHk.jpg Picture 1 code: main.css body { font-family: arial; font-size: 14px; color: #1D2130; background-image: linear-gradient(top, rgb(200,225,245) 15%, rgb(240,240,240) 60%); // more CSS properties h ...

Personalized Bootstrap grid rows and columns

https://i.sstatic.net/R0yFY.png As a beginner in Bootstrap, I am having trouble achieving this specific layout in Bootstrap 4 grid. The areas marked in red are not appearing as expected. Here is what I have attempted so far: <div class="row"> ...

Using -webkit-hyphens: auto in Safari does not function properly when the width is set to auto

I have a situation with an h3 element where I am unsure of its width. As a result, the width is set to auto by default. However, I need the text inside this element to have hyphenation applied to it. This h3 element is within a flex container along with an ...