Can I somehow use CSS to place the block2
in top right corner of block1
?
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
.block1
there could be <p>
, images, text and it is beyond my control to know what and how many.block2
to flow..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>
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; .
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.
.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.
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