How to get a responsive button in bootstrap 3

后端 未结 5 789
逝去的感伤
逝去的感伤 2020-12-13 02:05

I am using bootstrap 3 and I have the following html:


                      
相关标签:
5条回答
  • 2020-12-13 02:38

    For anyone who may be interested, another approach is using @media queries to scale the buttons on different viewport widths..

    Demo: http://bootply.com/93706

    0 讨论(0)
  • 2020-12-13 02:40

    In Bootstrap, the .btn class has a white-space: nowrap; property, making it so that the button text won't wrap. So, after setting that to normal, and giving the button a width, the text should wrap to the next line if the text would exceed the set width.

    #new-board-btn {
        white-space: normal;
    }
    

    http://jsfiddle.net/ADewB/

    0 讨论(0)
  • 2020-12-13 02:53
    <a href="#"><button type="button" class="btn btn-info btn-block regular-link"> <span class="text">Create New Board</span></button></a>
    

    We can use btn-block for automatic responsive.

    0 讨论(0)
  • 2020-12-13 02:54

    I know this already has a marked answer, but I feel I have an improvement to it.

    The marked answer is a bit misleading. He set a width to the button, which is not necessary, and set widths are not "responsive". To his defense, he mentions in a comment below it, that the width is not necessary and just an example.

    One thing not mentioned here, is that the words may break in the middle of a word and look messed up.

    My solution, forces the break to happen between words, a nice word wrap.

    .btn-responsive {
        white-space: normal !important;
        word-wrap: break-word;
    }
    
    <a href="#" class="btn btn-primary btn-responsive">Click Here</a>
    
    0 讨论(0)
  • 2020-12-13 03:02

    In some cases it's very useful to change font-size with relative font sizing units. For example:

    .btn {font-size: 3vw;}
    

    Demo: http://www.bootply.com/7VN5OCVhhF

    1vw is 1% of the viewport width. More info: http://www.sitepoint.com/new-css3-relative-font-size/

    0 讨论(0)
提交回复
热议问题