Place a button right aligned

后端 未结 11 1483
礼貌的吻别
礼貌的吻别 2020-12-22 15:56

I use this code to right align a button.

相关标签:
11条回答
  • 2020-12-22 16:11

    Another possibility is to use an absolute positioning oriented to the right. You can do it this way:

    style="position: absolute; right: 0;"
    
    0 讨论(0)
  • 2020-12-22 16:14

    If the button is the only element on the block:

    .border {
      border: 2px blue dashed;
    }
    
    .mr-0 {
      margin-right: 0;
    }
    .ml-auto {
      margin-left:auto;
    }
    .d-block {
      display:block;
    }
    <p class="border">
      <input type="button" class="d-block mr-0 ml-auto" value="The Button">
    </p>

    If there are other elements on the block:

    .border {
      border: 2px indigo dashed;
    }
    
    .d-table {
      display:table;
    }
    
    .d-table-cell {
      display:table-cell;
    }
    
    .w-100 {
      width: 100%;
    }
    
    .tar {
      text-align: right;
    }
    <div class="border d-table w-100">
      <p class="d-table-cell">The paragraph.....lorem ipsum...etc.</p>
      <div class="d-table-cell tar">
        <button >The Button</button>
      </div>
    </div>

    With flex-box:

    .flex-box {
      display:flex;
      justify-content:space-between;
      outline: 2px dashed blue;
    }
    
    .flex-box-2 {
      display:flex;
      justify-content: flex-end;
      outline: 2px deeppink dashed;
    }
    <h1>Button with Text</h1>
    <div class="flex-box">
    <p>Once upon a time in a ...</p>
    <button>Read More...</button>
    </div>
    
    <h1>Only Button</h1>
    <div class="flex-box-2">
      <button>The Button</button>
    </div>
    
    <h1>Multiple Buttons</h1>
    <div class="flex-box-2">
      <button>Button 1</button>
      <button>Button 2</button>
    </div>

    Good Luck...

    0 讨论(0)
  • 2020-12-22 16:19

    This would solve it.

    <input type="button" value="Text Here..." style="float: right;">
    

    Good luck with your code!

    0 讨论(0)
  • 2020-12-22 16:20

    Another possibility is to use an absolute positioning oriented to the right:

    <input type="button" value="Click Me" style="position: absolute; right: 0;">
    

    Here's an example: https://jsfiddle.net/a2Ld1xse/

    This solution has its downsides, but there are use cases where it's very useful.

    0 讨论(0)
  • 2020-12-22 16:21

    Which alignment technique you use depends on your circumstances but the basic one is float: right;:

    <input type="button" value="Click Me" style="float: right;">
    

    You'll probably want to clear your floats though but that can be done with overflow:hidden on the parent container or an explicit <div style="clear: both;"></div> at the bottom of the container.

    For example: http://jsfiddle.net/ambiguous/8UvVg/

    Floated elements are removed from the normal document flow so they can overflow their parent's boundary and mess up the parent's height, the clear:both CSS takes care of that (as does overflow:hidden). Play around with the JSFiddle example I added to see how floating and clearing behave (you'll want to drop the overflow:hidden first though).

    0 讨论(0)
  • 2020-12-22 16:21

    This solution depends on Bootstrap 3, as pointed out by @günther-jena

    Try <a class="btn text-right">Call to Action</a>. This way you don't need extra markup or rules to clear out floated elements.

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