Creating a stylish border for a clip path shape: A step-by-step guide

I'm attempting to design hexagon-shaped buttons with a transparent background and a white 1px border around the hexagon shape I've created using clip path. However, when I add the border, it gets cut off at parts. How can I fix this issue?

Below is my code:

  .project-button div{
      position: relative;
      display: inline-block;
      padding: 1rem;
      margin: 0 1rem 1rem 1rem;
      
      color: #d9d9d9;
      font-size: 1rem;
      font-weight: 700;
      border: 1px solid white;
    
      -webkit-clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
      clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
      
     
      background-repeat: no-repeat;
      transition: background-size .5s, color .5s;
    }
    
    .to-top {
        background-position: 50% 100%;
        background-size: 100% 0%;
      }
    
    .project-button div:hover {
        background-size: 100% 100%;
        background-image: linear-gradient(white, white);
        color: #51d0de;
    }
<div class="project-button">
   <div class="to-top>View Code</div>
</div>

Answer №1

Here is my progress so far,
I implemented filter: drop-shadow()

To achieve a transparent background, you can use the same color as the parent element

.hexagon{
  background: white;/*it is crucial to specify a color*/
  padding: 40px;
  width: 20%;
  text-align: center;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}
/* main code */
.container{
  filter: drop-shadow(0px 0px 1px black);
}
  <div class="container">
    <div class="hexagon">Button</div> 
  </div>

I hope this information proves useful.

Just a reminder: make sure to apply the filter to the parent 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

Show images exclusively on screens with a smaller resolution

Looking for assistance in modifying the code below to only display the image in mobile view, instead of constantly appearing. <style type="text/javascript> .icon-xyz {float: left; width: 22px;cursor: pointer;background: none;} @me ...

Transitioning the color of links in Firefox causes flickering when switching between the hover and visited state

I have been working on testing this code snippet in Firefox 49.0 on Linux Mint: a{ font-size:50px; color:gray; font-weight:1000; transition:color 1s; } a:hover{ color:black; } a:visited{ color:lightgray; } <a href="">VISITED LINK</a>&l ...

``Please proceed with the form submission only if it has been verified and

Within my web application, there are several pages that handle submitted data from forms. I would like to prevent the following scenario: A user creates a form on the client side with identical fields to my original form and sends it to the URL responsibl ...

Why won't applying a binding style affect the appearance of my Vue component?

const EventLevelBoard = { name: "EventLevel", data: { levelStyle: { display: "block" }, levelStyleinner: [ { display: "block" }, { display: "block" }, { display: "block&qu ...

Add a <div> element to a webpage in a random location every time the page is refreshed

I have a variety of 2 types of <div>s displayed on a single page. Collection 1 consists of: <div class="feature">content 1</div> <div class="feature">content 2</div> ...and so forth. Collection 2 consists of: <div class ...

Is there a way to retrieve all "a" tags with an "href" attribute that contains the term "youtube"?

My goal is to capture all a tags that have the href attribute containing the word youtube. This task requires the use of jquery. ...

Issue with nav-pill not functioning properly on localhost server set up with XAMPP

<!-- Customized Navigation Pills --> <ul class="nav nav-pills" role="tablist"> <li class="nav-item"> <a class="nav-link active" data-toggle="pill" href="#home">My Home</a> </li> <li class="nav-item ...

The hyperlink is unclickable because of the menu

The code below contains a menu on the right side with a hover effect and some content with a link. However, the link is not clickable due to the menu. .menubar{position: fixed;right:0;top: 50%;transform: translateY(-50%);-webkit-transform: translateY(-5 ...

What is the best method for inserting a URL link using jQuery within a CSS element?

Check out this code snippet: <span class='maincaptionsmall'> Test </span> Due to certain ajax and jquery scripts on my page, I am unable to use HREF as a link. In other words, the following code won't work: <span class=&ap ...

Tips for adjusting the number of columns in a list display using CSS

Recently, I decided to delve into the world of CSS and Bootstrap. I came across an interesting example that I'm trying to implement in my project. You can find the example here. Here's the HTML code snippet: <div class="container"&g ...

Format the image to fit within a div container

I'm currently utilizing Bootstrap and am looking to insert some images into my div while ensuring they are all the same size (standardized). If the images are too large (as they typically are), I want to resize them to fit within my div and crop them ...

Looking for a quicker loading time? Opt for a shortened version of CSS

Most of the images on my website are optimized using sprite sheets, where multiple images are combined into one file to enhance user experience. This method reduces the number of server requests for individual images. However, I'm facing an issue whe ...

The slider feature is malfunctioning on Internet Explorer version 8

Hello everyone, I am facing an issue with my website located at: http://210.48.94.218/~printabl/ When viewed in IE 8, the slider is not functioning properly (it is showing collapsed between the menu and product images section) The theme used for my site ...

Progress Circles on Canvas in FireFox

Currently, I am experimenting with this codepen demo that utilizes canvas to generate progress circles: The functionality functions perfectly in Chrome and Safari; however, it only displays black circles in FireFox. My knowledge of canvas is limited, so I ...

Efficiently storing multiple file fields in Django with the help of jQuery and Ajax

I need assistance with saving multiple file fields to a server. The fields are dynamic, allowing users to upload as many files as they want using an add button. I prefer not to use form submit or dropzone. Can someone please advise me on how to achieve thi ...

Mastering the art of flawlessly executing kerning-generated code

I am facing a problem while implementing logotext with kerning technique in the <header> element. I found a useful tool made by Mr. Andrew which can be accessed through this link. Before making any modifications, I had the following code in the heade ...

Learn how to manipulate the DOM by dynamically creating elements and aligning them on the same line

Providing some context for my page: The section I have always contains a single input field. Below that, there is an "add" button which generates additional input fields. Since only one field is required on the screen, the following fields come with a "de ...

In the readmore.js script, position the "readmore" link within a div instead of outside of it

I have added annotations that vary in length, so I am looking to integrate the readmore.js plugin. To ensure uniform sizing for all annotations (even empty ones), I need to set a minimum height for the div container. <annotation> <div style="wi ...

What is the method to incorporate spread into inner shadow within an SVG file?

Seeking assistance with creating an inset-shadow effect with spread for an SVG rectangle in Figma. Check out this example of a rectangle with inner-shadow and spread. I have successfully added blur and positioned the shadow using x and y coordinates, but ...

Slide-out left menu using HTML and CSS

Currently, I am in the process of constructing a website that requires a menu to gracefully slide from the left side of the screen (with a width of 0px) to the right side (expanding to a width of 250px), all with the help of jQuery animations. Here is wha ...