Positioning a div inside a div without affecting the layout

I have div( div1), which has its position, width, height, everything that is installed and it is installed from the outside, so I can’t know in advance what these values ​​are.

Inside and at the top div1is another div( div2). I want to div2swim to the right of div1without affecting the following information in div1.

I can add an attribute position:absoluteand get div2to float and not affect the contents, however I cannot make it float to the right, even when applied float:right.

+3
source share
4 answers

If I understand correctly:

position: relative div1.

, float: right position: absolute div2, float: right right: 0.

+7

:

position: absolute;
right: 0;
top: 0;
+3

with relative positioning?

<div style="height:300px;width:300px;position:relative;background-color:red">
  <div style="height:100px;width:100px;position:relative;float:right;background-color:yellow">
</div>
+1
source

Did you try to put different contents of div1 in another div, and then set the specified width in that div while keeping float: directly on div2. Sounds like a sidebar style script.

0
source

Source: https://habr.com/ru/post/1794854/


All Articles