0

I have multiple div with property float left and width 50% because i want next div to be appear right to the current div and another div in bottom or next line. (I am printing it in foreach loop)

<div class="row" style="width:100%;">

<div class="" style="width:50%;float:left;">
  <div style="font-size:14px;color: #500050;">
    <p class="abc">ABC</p>
  </div>
  <div style="font-size: 12px;color: black;">
    <span>23:54</span>&nbsp;
    <span>ABC</span><br/>
    <span>dsds</span><br/>
    <span>dsfsafsaf sdsad ad</span>
  </div>
</div>

<div class="" style="width:50%;float:left;">
  <div style="font-size:14px;color: #500050;">
    <p class="">XYZ</p>
  </div>      
  <div style="font-size: 12px;color: black;">
    <span>time </span>&nbsp;
    <span>$value->type </span><br/>
    <span>subtype </span><br/>
    <span> description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj</span>
    <span> description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj</span>
    <span> description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj</span>
  </div>
</div>

<div class="" style="width:50%;float:left;">
  <div style="font-size:14px;color: #500050;">
    <p class="">PQR</p>
  </div>      
  <div style="font-size: 12px;color: black;">
    <span>time </span>&nbsp;
    <span>type </span><br/>
    <span> subtype </span><br/>
    <span> description </span>
  </div>
</div>

it is working fine till this but if second div height is more than first on then first div adjust its height equal to second div and third div appear below first div as follow

ABC                                XYZ
23:54  ABC                         time   $value->type
dsds                               subtype 
dsfsafsaf sdsad ad                 description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj 
                                   description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj 
                                   description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj
PQR 
time   type 
subtype 
description

but i want it as

ABC                                XYZ
23:54  ABC                         time   $value->type
dsds                               subtype 
dsfsafsaf sdsad ad                 description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj
                                   description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj description sjgdvhgsa 
PQR                                description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj description sjgdvhgsa
time   type 
subtype 
description

What should be done ?

Vishal B
  • 653
  • 2
  • 12
  • 31

1 Answers1

1

give float:right to second div instead of float: left

As you are using in a loop give class instead of inline styles and css

.block {
width: 50%;
}
.block:nth-child(odd) {
float: left;
}
.block:nth-child(even) {
float: right;
}
 

        <div class="row" style="width:100%;">
        
        <div class="block">
          <div style="font-size:14px;color: #500050;">
            <p class="abc">ABC</p>
          </div>
          <div style="font-size: 12px;color: black;">
            <span>23:54</span>&nbsp;
            <span>ABC</span><br/>
            <span>dsds</span><br/>
            <span>dsfsafsaf sdsad ad</span>
          </div>
        </div>
        
        <div class="block">
          <div style="font-size:14px;color: #500050;">
            <p class="">XYZ</p>
          </div>      
          <div style="font-size: 12px;color: black;">
            <span>time </span>&nbsp;
            <span>$value->type </span><br/>
            <span>subtype </span><br/>
            <span> description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj</span>
            <span> description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj</span>
            <span> description sjgdvhgsa sajgdjh asdgsdj sadfsajgd fjsad sajfdj sa fdja dhsj</span>
          </div>
        </div>
        
        <div class="block">
          <div style="font-size:14px;color: #500050;">
            <p class="">PQR</p>
          </div>      
          <div style="font-size: 12px;color: black;">
            <span>time </span>&nbsp;
            <span>type </span><br/>
            <span> subtype </span><br/>
            <span> description </span>
          </div>
        </div>
Supraja Ganji
  • 1,187
  • 1
  • 6
  • 8