Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polygon border / border radius of a button

I am trying to make polygon border shape like image below.

poygon border button background

The code i have tried is below.

@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');

.p-button{
  background: transparent;
  text-decoration: none;
  background: #5344c6;
  color: white;
  padding: 15px 50px;
  border-radius: 27px;
  text-transform: uppercase;
  font-family: "Poppins";
  letter-spacing: 0.5px;
}

body{
  display: flex;
  height: 100vh;
  align-items: center;
  justify-content: center;
  
}
<a class="p-button" href="">Explore The Tech</a>
like image 531
Foss Bytes Avatar asked Jul 24 '21 06:07

Foss Bytes


People also ask

What is border-radius in CSS?

The border-radius CSS property rounds the corners of an element's outer border edge. You can set a single radius to make circular corners, or two radii to make elliptical corners.

Why border-radius is not working?

Your problem is unrelated to how you have set border-radius . Fire up Chrome and hit Ctrl+Shift+j and inspect the element. Uncheck width and the border will have curved corners. Show activity on this post.

Why does my button border radius look different on each page?

You are using different Font sizes in buttons that's why buttons border radius is looking different, You can solve this issue using border-radius : 60px; in both buttons css and if you want to set same height you can use min-height.

What is a button border?

Introduction to CSS Button Border In this article, we are discussing button borders in CSS. In general, a button is a clickable event that is used in elements for which when we click on the button it will take to another page or element or some other action to be performed. In this article, let us see how the borders are applied to the buttons.

How do I create a polygon border using CSS?

In order to achieve the polygon border, I am going to rely on a combination of the CSS clip-path property and a custom mask created with the Paint API. We start with a basic rectangular shape. We apply clip-path to get our polygon shape. Nothing complex so far but note the use of the CSS variable --path.

What is the use of border radius?

Definition and Usage. The border-radius property defines the radius of the element's corners. Tip: This property allows you to add rounded corners to elements! This property can have from one to four values. Here are the rules:


Video Answer


1 Answers

Use clip-path:

@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');

.p-button{
  background: transparent;
  text-decoration: none;
  background: #5344c6;
  color: white;
  padding: 15px 50px;
  text-transform: uppercase;
  font-family: "Poppins";
  font-size:40px;
  --h:45px; /* this is half the height, adjust it based on your code */
  clip-path:polygon(
    0 50%,
    calc(0.134*var(--h))  25%,   /* 0.134 = 1 - cos(30)   */
    calc(  0.5*var(--h))  6.7%,  /* 6.7% = 0.134/2 * 100% */
    var(--h) 0,
    calc(100% - var(--h)) 0,
    calc(100% - 0.5*var(--h))   6.7%,
    calc(100% - 0.134*var(--h)) 25%,
    100% 50%,
    calc(100% - 0.134*var(--h)) 75%,
    calc(100% - 0.5*var(--h))   93.3%, /* 93.3% = 100% - 6.7% */
    calc(100% - var(--h)) 100%,
    var(--h) 100%,
    calc(  0.5*var(--h))  93.3%,
    calc(0.134*var(--h))  75%);
}

body{
  display: flex;
  height: 100vh;
  align-items: center;
  justify-content: center;
  
}
<a class="p-button" href="">Explore The Tech</a>
like image 157
Temani Afif Avatar answered Oct 20 '22 13:10

Temani Afif