slkhan
slkhan

Reputation: 161

How to set margins to two div inside another div?

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.

Upvotes: -1

Views: 62

Answers (2)

iamrajshah
iamrajshah

Reputation: 979

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>

Upvotes: 1

Mayur Parmar
Mayur Parmar

Reputation: 264

enter this code inside div

margin: 5px auto;

Upvotes: 3

Related Questions