Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to place last div into right top corner of parent div? (css)

Tags:

html

css

Can I somehow use CSS to place the block2 in top right corner of block1?


Context :

  • block2 must be the (very) last inside HTML code of block1 or it could be placed after block1. I can't make it the first element in block1.
  • Within block1 there could be <p>, images, text and it is beyond my control to know what and how many.
  • Also I need the block2 to flow.

Code :

.block1 {     color: red;     width: 100px;     border: 1px solid green; }  .block2 {     color: blue;     width: 70px;     border: 2px solid black;     position: relative; }
<div class='block1'>     <p>text</p>     <p>text2</p>     <div class='block2'>block2</div> </div>
like image 789
Radek Avatar asked May 16 '10 02:05

Radek


People also ask

How do you put a div in the top right corner?

you can play with the top and right properties. If you want to float the div even when you scroll down, just change position:absolute; to position:fixed; .

How do I put a div on the right side of another div?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.


1 Answers

.block1 {      color: red;      width: 100px;      border: 1px solid green;      position: relative;  }    .block2 {      color: blue;      width: 70px;      border: 2px solid black;      position: absolute;      top: 0px;      right: 0px;  }
<div class='block1'>    <p>text</p>    <p>text2</p>    <div class='block2'>block2</div>  </div>

Should do it. Assuming you don't need it to flow.

like image 163
prodigitalson Avatar answered Sep 28 '22 19:09

prodigitalson