-1

I want to set different margins to two divs, inside another div. The first div should appear top of the second div.

<div style="position:relative">
 <div style="position: absolute;margin-top:24px">
   This should be appar top of the second div.
 </div>
 <div style="margin-top:24px">
   second div
 </div>
</div

I used above mention code, but first div also getting margin 50, not margin 24.
How to resolve this issue?
Cannot use position:absoulte to the second div.

iamrajshah
  • 963
  • 1
  • 11
  • 23
slkhan
  • 101
  • 1
  • 9

2 Answers2

3

enter this code inside div

margin: 5px auto;
Sujal Patel
  • 2,444
  • 1
  • 19
  • 38
Mayur Parmar
  • 224
  • 1
  • 8
1

You can use the following code:

   <div style="position:relative">
     <div style="posiotion:absolute, top:24px">
       This should be appar top of the second div.
     </div>
     <div>
       second div
     </div>
   </div>
slkhan
  • 101
  • 1
  • 9
iamrajshah
  • 963
  • 1
  • 11
  • 23