Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. CSS
  4. How to create buttons of specific shape

How to create buttons of specific shape

Scheduled Pinned Locked Moved CSS
2 Posts 2 Posters 41 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Valentinor
    wrote last edited by
    #1

    How can you create in HTML with CSS buttons to have this shape?

    I want them all to have the same width based on the text and some padding, and be centered inside a div. Also I do want those lines at the sides to be included as well, as they make them look nicer and also give you a sense of the button space/size.

    d03adb92-6f4a-4d1e-98ee-5a7601d05c3b-image.png

    That example I made in a desktop app and can not be translated, as it is not HTML based.

    1 Reply Last reply
    0
    • Graeme_GrantG Offline
      Graeme_GrantG Offline
      Graeme_Grant
      wrote last edited by Graeme_Grant
      #2

      image.png

      Use a simple clip-path polygon... then negative margin to pull them closer for the border appearance.

      Something like this:

      <!DOCTYPE html>
      <html lang="en">
          <head>
              <meta charset="UTF-8" />
              <meta name="viewport" content="width=device-width, initial-scale=1.0" />
              <title>Diamond Navigation</title>
              <style>
                  body {
                      margin: 0;
                      padding: 50px;
                      font-family: Arial, sans-serif;
                      background-color: #e5e5e5;
                  }
      
                  .diamond-nav {
                      display: flex;
                      align-items: center;
                      justify-content: center;
                      margin: 0 auto;
                      width: fit-content;
                      height: 50px;
                      padding: 4px 17px;
                      background-color: #2d3748;
                      border-radius: 8px;
                  }
      
                  .nav-item {
                      display: flex;
                      align-items: center;
                      justify-content: center;
                      height: 50px;
                      line-height: 50px;
                      padding: 0 30px;
                      margin-inline: -5px;
                      box-sizing: border-box;
                      white-space: nowrap;
                      background-color: #4f5a6b;
                      color: white;
                      text-decoration: none;
                      font-size: 14px;
                      font-weight: 400;
                  }
      
                  /* Left group - both point left */
                  .nav-item:nth-child(1),
                  .nav-item:nth-child(2) {
                      clip-path: polygon(15px 0, 100% 0, calc(100% - 15px) 50%, 100% 100%, 15px 100%, 0 50%);
                  }
      
                  /* Center group - points both ways */
                  .nav-item:nth-child(3) {
                      clip-path: polygon(15px 0, calc(100% - 15px) 0, 100% 50%, calc(100% - 15px) 100%, 15px 100%, 0 50%);
                  }
      
                  /* Right group - both point right */
                  .nav-item:nth-child(4),
                  .nav-item:nth-child(5) {
                      clip-path: polygon(0 0, calc(100% - 15px) 0, 100% 50%, calc(100% - 15px) 100%, 0 100%, 15px 50%);
                  }
      
                  /* Active state styling */
                  .nav-item.active {
                      background-color: #b8860b;
                  }
      
                  /* Hover effects */
                  .nav-item:hover {
                      background-color: #5a6578;
                  }
      
                  .nav-item.active:hover {
                      background-color: #cd950c;
                  }
              </style>
          </head>
          <body>
              <div class="diamond-nav">
                  <a href="#" class="nav-item">Left 2</a>
                  <a href="#" class="nav-item">Left 1</a>
                  <a href="#" class="nav-item active">Center</a>
                  <a href="#" class="nav-item">Right 1</a>
                  <a href="#" class="nav-item">Right 2</a>
              </div>
          </body>
      </html>
      

      I have done the heavy lifting for you. If you want borders, then I'll leave that one to you 😉

      ps: As another thought, you could rotate the elements 45 degrees and use the parent as a clip region to give the top and bottom a flat edge ... but I will leave you to experiment with it...

      “I fear not the man who has practised 10,000 kicks once, but I fear the man who has practised one kick 10,000 times.” - Bruce Lee.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups