Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS custom shape with irregular rectangle and border

Tags:

css

css-shapes

I'm trying to create a button like this:

enter image description here

After researching online, I only came up with making a parallelogram. But this is the result:

enter image description here

Code:

.parallelogram {
  width: 100px;
  height: 50px;
  transform: skew(25deg);
  background: black;
  border: 1px solid #EC00F4;
  color: white;
  box-shadow: 0px 3px 8px #EC00F4;
}
<button class="parallelogram"> Hello button </button>

Is there a way to make the edges go where I want (like in the picture) but without moving the text ?

like image 258
IkePr Avatar asked Sep 05 '25 23:09

IkePr


2 Answers

Use clip-path on pseudo elements. The trick is to consider the same clip-path and apply a scale transformation to one pseudo element to simulate the border. Simply adjust the value of the polygon to get the needed result.

Hover to see a different clip-path:

.parallelogram {
   padding:20px 45px;
   font-size:30px;
   color: white;
   border:none;
   background:none;
   outline:none;
   position:relative;
   z-index:0;
   margin:15px;
   filter:drop-shadow(0px 30px 25px rgba(236, 0, 244, 0.45));
}
.parallelogram:before,
.parallelogram:after {
   content:"";
   position:absolute;
   z-index:-1;
   top:0;
   left:0;
   right:0;
   bottom:0;
   clip-path: polygon(0 11%, 100% 0, 90% 88%, 3% 96%);
   transition:1s all;
   background:#000;
}
.parallelogram:before {
  background:#EC00F4;
  transform:scale(1.05,1.12);
}

.parallelogram:hover:before,
.parallelogram:hover:after {
   clip-path: polygon(5% 2%, 100% 5%, 100% 100%, 0% 94%);
}
<button class="parallelogram"> Hello button </button>
<button class="parallelogram"> button </button>
<button class="parallelogram"> A </button>

You can also consider pixel value to keep the same shape whataver the content inside:

.parallelogram {
   padding:20px 45px;
   font-size:30px;
   color: white;
   border:none;
   background:none;
   outline:none;
   position:relative;
   z-index:0;
   margin:15px;
   filter:drop-shadow(0px 30px 25px rgba(236, 0, 244, 0.45));
}
.parallelogram:before,
.parallelogram:after {
   content:"";
   position:absolute;
   z-index:-1;
   top:0;
   left:0;
   right:0;
   bottom:0;
   clip-path: polygon(0 10px, 100% 0, calc(100% - 8px) calc(100% - 15px), 5px calc(100% - 8px));
   transition:1s all;
   background:#000;
}
.parallelogram:before {
  background:#EC00F4;
  transform:scale(1.05,1.12);
}

.parallelogram:hover:before,
.parallelogram:hover:after {
   clip-path: polygon(0 5px, 100% 0, 100% 100%, 10px calc(100% - 20px));
}
<button class="parallelogram"> Hello button </button>
<button class="parallelogram"> button </button>
<button class="parallelogram"> A </button>
like image 98
Temani Afif Avatar answered Sep 09 '25 01:09

Temani Afif


This works kinda like you want it:

button{
   width: 150px;
   height: 50px;
   -webkit-clip-path: polygon(0% 20%, 92% 14%, 88% 88%, 0% 100%);
   clip-path: polygon(0% 20%, 92% 14%, 88% 88%, 0% 100%);
   background: black;
   color: white;
}
<button class="parallelogram"> Hello button </button>

EDIT:

You can create an SVG that looks exactly like your button here: https://vectr.com/new

You can add border + shadow and simply copy the html.

like image 26
sina_r Avatar answered Sep 09 '25 02:09

sina_r