I am trying to fix a button to the right edge of a div.
HTML:
<div id="header">
<button type="button" uk-toggle="target: #offcanvas-flip" uk-icon="icon: plus"></button>
</div>
CSS:
#header {
margin-left: 240px;
background-color: #0070e0;
padding: 20px;
position: relative;
}
#header > button {
position: absolute;
top: 10px;
right: 10px;
color: #ffffff;
}
After applying position: absolute
:
You can see in the image above that original
padding: 20px
on the parent div is ignored.
While removing position: absolute
:
Brings the original padding back but as you can see the
button
is then not to the right. Applying float: right
has the same effect.
Can somebody help me fix this issues and more importantly explain whats causing this so I can better learn. Apologies if this is a very basic question.