Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding button to top right of block level elements

Tags:

html

css

How would I add a button to the top right of block level elements? Lets say i have :

<div>some content here</div>

and lets say this content is long enough to make a "block", how would I format to have a button at the TOP RIGHT of the block, right next to the block that is?

like image 658
re1man Avatar asked Oct 19 '25 15:10

re1man


1 Answers

(1) One way is to float the button right at the top of the container.

<div><button>My Button</button>some content here</div>

div + button {
float: right;
}

(2) Another way is to position the button absolutely inside the div container and give the div container position (so that elements postioned absolutely inside it are relative to this container). This way the button can be anywhere in the markup, providing it is inside the container.

div {
position: relative;
}

div button {
position: absolute;
top: 0;
right: 0;
}

However, the button will now be on top of other content inside the container so you might have to adjust this with padding etc.

like image 116
MrWhite Avatar answered Oct 21 '25 06:10

MrWhite