Search code examples
htmlcssuser-experience

Display text on a html button


I need to create buttons for two respective labels - Live Server and WebApi like this : enter image description here

The numbers displayed on the buttons should be binded through data-bind property. For now, I just want to know how can I display these numbers on the top of each button (without using data-bind).

I have done something like this:

#buttons {
    width: auto;
    margin: 0 auto;
    padding: 3px;
  display: flex;
}

.label {
    font-size: medium;
    position: absolute;
}

#l2 {
    width: 100px;
    justify-content:center;
    position: relative;
}

#block2 {
    display: flex;
    justify-content: center;
}

small {
    display: inline;
    text-align: center;
   border: 1px solid black;
}

.stats{
  justify-content: center;
}
.small {
    height: 40px;
    width: 80px;
    background-color: antiquewhite;
}

.button{
    height: 40px;
    width: 120px;
    background-color: lightblue;
    display: flex;

} 
<div id="block2"><div id="l2"><label class="label label2">WebApi</label></div>
<div id ="buttons">
       <div class="button">
            <div><button class="k-button button5 small" id="b5" >PUT</button></div>
            <div class="stats"><small>10</small></div>
       </div>

       <div class="button">
            <div><button class="k-button button6 small" id="b6">POST</button></div>
            <div class="stats"><small>30</small></div>
       </div>

       <div class="button">
            <div><button class="k-button button7 small" id="b7">GET</button></div>
            <div class="stats"><small>16</small></div>
       </div>

       <div class="button">
            <div> <button class="k-button button8 small" id="b8">PENDING</button></div>
            <div class="stats"><small>25</small></div>
       </div>
</div>
</div>


Solution

  • You are on a right track just put that number div inside that button and use flex

    #buttons {
        width: auto;
        margin: 0 auto;
        padding: 3px;
      display: flex;
    }
    
    .label {
        font-size: medium;
        position: absolute;
    }
    
    #l2 {
        width: 100px;
        justify-content:center;
        position: relative;
    }
    
    #block2 {
        display: flex;
        justify-content: center;
    }
    
    small {
        display: inline;
        text-align: center;
       border: 1px solid black;
    }
    
    .stats{
      justify-content: center;
    }
    .small {
        height: 40px;
        width: 80px;
        background-color: antiquewhite;
    }
    
    .button{
        height: 40px;
        width: 120px;
        background-color: lightblue;
        display: flex;
    
    } 
    .k-button{
      display: flex;
     justify-content: space-around;
     min-width: 100px;
    }
    
    }
    <div id="block2"><div id="l2"><label class="label label2">WebApi</label></div>
    <div id ="buttons">
           <div class="button">
                <div><button class="k-button button5 small" id="b5" >PUT  <div class="stats"><small>30</small></div></button></div>
                
           </div>
    
           <div class="button">
                <div><button class="k-button button6 small" id="b6">POST <div class="stats"><small>30</small></div></button></div>
               
           </div>
    
           <div class="button">
                <div><button class="k-button button7 small" id="b7">GET<div class="stats"><small>16</small></div></button></div>
                
           </div>
    
           <div class="button">
                <div> <button class="k-button button8 small" id="b8">PENDING<div class="stats"><small>25</small></div></button></div>
                
           </div>
    </div>
    </div>