Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a button full height of the parent container and right-aligned?

I am using Bootstrap and I want add a button at right of a bar that looks like <input-group-addon>. To be specific, full height and locates at right most.

I've tried height: 100% but the button styles super high.

this is part of my code: https://plnkr.co/edit/lK8vt0wT1xDesuOZW8vU?p=preview

this is what I m looking for enter image description here

like image 861
Zanecat Avatar asked Jul 19 '17 05:07

Zanecat


People also ask

How do you make a button on the right side?

If you want to move the button to the right, you can also place the button within a <div> element and add the text-align property with its "right" value to the "align-right" class of the <div>.

How do I left align a button in CSS?

Add css style using adding the margin-left property referencing the button. The following code snippet can be a positive or negative number to shift the button left or right. Typically if you used the button solution, add the margin-left property as in the screen shot - or add the code below in a custom html block.


1 Answers

Try absolutely positioning your button:

.my-heading {
  position: relative;
}

.btn.my-btn {
  position:absolute;
  right: 0;
  top: 0;
  height: 100%;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
<head>
  <link rel="stylesheet" href="style.css">
  <script src="script.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>
  <div class="panel panel-default">
    <div class="panel-heading my-heading">Assist Panel<button class="my-btn btn"><i class="fa fa-chevron-left"></i></button></div>
    <div class="panel-body"></div>
  </div>
</body>
like image 53
fen1x Avatar answered Sep 22 '22 14:09

fen1x