Centering text within a button

后端 未结 3 2105
日久生厌
日久生厌 2021-02-12 11:52

I\'m learning Front end development and I\'m trying to code my first site using bootstrap. I got stuck on a pretty simple thing I guess. How do I center a text within a button

相关标签:
3条回答
  • 2021-02-12 12:36

    In here you make a link as a button. You can make a button inside tag.

     <a class="btn btn-default btn-work" href=""><input type="button" class="btn btn-default btn-work" value="Check my work"/></a>
    
    0 讨论(0)
  • 2021-02-12 12:45

    See this fiddle

    Use

    display: table-cell;
    vertical-align: middle;
    

    in your CSS for .btn-work.

    So, the complete CSS would be like

    .btn-work {
        width: 250px;
        height: 50px;
        margin: 0 auto;
        padding: 0;
        display: table-cell;
        vertical-align: middle;
    }
    

    And, the output of the above one be like

    0 讨论(0)
  • 2021-02-12 12:57

    To center the text within the button. Use this code.

    .btn-work{ text-align: center; }
    

    To center the button, use a parent div to align it to center.

    CSS:

     div.parentElement{text-align: center;}
     .btn-work{ display: inline-block; }
    

    HTML:

    <div class="parentElement">
        <a class="btn btn-default btn-work" href="#">Check my work</a>
    </div>
    

    Full CSS:

    div.parentElement{text-align: center;}
    
    .btn-work {
        width: 250px;
        height: 50px;
        margin: 0 auto;
        padding: 0;
        display: inline-block;
        line-height: 50px;
        text-align: center;
    }
    
    0 讨论(0)
提交回复
热议问题