http://jsfiddle.net/kn5sH/
What do I need to add in order to stick the button to the right side of the div on the same line as the header?
HTML:
<div> <h1> Ok </h1> <button type='button'>Button</button> </div>
CSS:
div { background: purple; } div h1 { text-align: center; } div button { }
More specifically:
What CSS techniques can be used to do this? Thanks.
The right side of the button should be x pixels away from the right edge of the div. It should be on the same line as the header. Should be contained in the div (stuff like float or relative positioning pops it out of the div visually)
You can also move you button to right by applying text-align: right; to it's parent. In your case it's parent is body.
Answer: Use the text-right Class You can simply use the class . text-right on the containing element to right align your Bootstrap buttons within a block box or grid column. It will work in both Bootstrap 3 and 4 versions.
Approach #1: Use align-self: flex-end on the button. This would make the button appear in the rightmost corner of your parent. Approach #2: In case you want more control over the position of the button in terms of alignment with the text area, you can wrap the button in a div and keep the float right on the button.
Normally I would recommend floating but from your 3 requirements I would suggest this:
position: absolute; right: 10px; top: 5px;
Don't forget position: relative;
on the parent div
DEMO
Another solution: change margins. Depending on the siblings of the button, display
should be modified.
button { display: block; margin-left: auto; margin-right: 0; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With