skip to Main Content

This is the (wrong) code for it:

.btn-group .button {
  background-color: #fffff1;
  border: 0px solid black;
  border-radius: 8px;
  border-bottom: 1px solid black;
  color: #3c4043;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  font-size: 16px;
  cursor: pointer;
  width: 150px;
  display: block;
}

.button1 {
  border-bottom: 1px solid black;
}

.btn-group .button:not(:last-child) {
  
}

.btn-group .button:hover {
  background-color: #fffff1;
  box-shadow: 0 0px 4px 0 rgba(0,0,0,0.24), 0 0px 32px 0 rgba(0,0,0,0.19);
}
<!DOCTYPE html>
<html>
<head>

</head>
<body>


<div class="btn-group">
  <button class="button button1">Button</button>
  <button class="button button2">Button</button>
  <button class="button button3">Button</button>
  <button class="button button4">Button</button>
</div>

</body>
</html>

The required result ( the image is photoshopped ) :
image
( help me please )

im trying to limit the border on the butttons length to a certain size

3

Answers


  1. You can do this using pseudo elements. Here is the code:

    .btn-group .button {
      background-color: #fffff1;
      border: 0px solid black;
      border-radius: 8px;
     /* border-bottom: 1px solid black;*/
      color: #3c4043;
      padding: 15px 32px;
      text-align: center;
      text-decoration: none;
      font-size: 16px;
      cursor: pointer;
      width: 150px;
      display: block;
    }
    
    .button {
    position: relative;
    margin-bottom: 1rem;
    box-sizing:border-box;
    }
    
    .button::after{
      content: '';
      position: absolute;
      bottom: 0;
      width: 100px;
      height: 1px;
      background: black;
      left: 50%;
      transform: translateX(-50%);
    }
    
    .button1 {
     /* border-bottom: 1px solid black;*/
    }
    
    .btn-group .button:not(:last-child) {
      
    }
    
    .btn-group .button:hover {
      background-color: #fffff1;
      box-shadow: 0 0px 4px 0 rgba(0,0,0,0.24), 0 0px 32px 0 rgba(0,0,0,0.19);
    }
    <!DOCTYPE html>
    <html>
    <head>
    
    </head>
    <body>
    
    
    <div class="btn-group">
      <button class="button button1">Button</button>
      <button class="button button2">Button</button>
      <button class="button button3">Button</button>
      <button class="button button4">Button</button>
      <button class="button button4">Button</button>
      <button class="button button4">Button</button>
    </div>
    
    </body>
    </html>
    Login or Signup to reply.
  2. You can use the pseudo element after to make this work. Here are the changes i made that you should be weary of:

    .button {
      background-color: salmon /* so you can see the changes easier */
      position: relative /* this is so we can anchor the :after element */
    }
    .button:after {
      content: "";
      background: black;
    
      /* so we can adjust the position of the border bottom */
      position: absolute;
    
      /* bottom: 0 is to put it at the bottom*/
      bottom: 0;
    
      /* left: 5% is to center it */
      left: 5%;
    
      height: 1px;
      width: 90%;
    }
    
    .btn-group .button {
      /* background-color: #fffff1; */
      background-color: salmon;
      border: none;
      border-radius: 8px;
      color: #3c4043;
      padding: 15px 32px;
      text-align: center;
      text-decoration: none;
      font-size: 16px;
      cursor: pointer;
      width: 150px;
      display: block;
      position: relative;
    }
    
    .btn-group .button:after {
      content: "";
      background: black;
      position: absolute;
      bottom: 0;
      left: 5%;
      height: 1px;
      width: 90%;
    }
    
    .btn-group .button:hover {
      background-color: #fffff1;
      box-shadow: 0 0px 4px 0 rgba(0,0,0,0.24), 0 0px 32px 0 rgba(0,0,0,0.19);
    }
    <!DOCTYPE html>
    <html>
    <head>
    
    </head>
    <body>
    
    
    <div class="btn-group">
      <button class="button button1">Button</button>
      <button class="button button2">Button</button>
      <button class="button button3">Button</button>
      <button class="button button4">Button</button>
    </div>
    
    </body>
    </html>
    Login or Signup to reply.
  3. You could set a max width to your button. That would restrict the border only to the width you define.

    .btn-group .button{
        max-width: 20px;
    }
    

    You can put any value, 20px is just a random value you can adjust according to your own needs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search