Align content inside Div

THAT I LOVE

I have this table.

enter image description here

With this HTML

<div class="list-item">
<p>
 <input type="checkbox">
 <span class="list-type"><img src="/images/types/{{this.type}}.png" title="{{this.type}}" /></span> 
 <span class="list-title">{{this.title}}</span> 
 <span class="list-owner">{{this.owner}}</span>
 <span class="list-date">16 Dec 2014</span>
</p>
 </div><br>

      

With this CSS

.list-item{
  display: inline-block;
  width: 100%;
  border: solid 1px #dddddd;
}

.list-type{
  margin-left: 10px;
  margin-right: 10px;
}

      

WHAT I WANT TO DO

But I want to create something like a table inside <div>

.

NOTE I KNOW a is <table>

perfect, but for the way this content is beigned I need to simulate the table using this <div>

, so the unorntannly table is not an option here.

I need to reproduce something like this (check the image).

enter image description here

NOTE Ignore the star icon

WHAT I'M ALREADY TRYING


Settin margin-left

for each <span>

, but the order of "admin" and "date" is not equal, if I use the fields I get this (check the image).

enter image description here

I get it with this CSS

.list-item{
  display: inline-block;
  width: 100%;
  border: solid 1px #dddddd;
}

.list-type{
 margin-left: 10px;
}

.list-title{
   margin-left: 10px;
}

.list-owner{
  margin-left: 100px;
}

.list-date{
  margin-left: 190px;
}

      

+3


source to share


4 answers


I changed some tags and some CSS, I like using percentage widths and divs. If that doesn't help you, maybe it might give you more ideas.



.list-item{
  display: inline-block;
  width: 100%;
  border: solid 1px #dddddd;
}
.cb{
    float: left;
    width:3%;
}
.list-type{
    float: left;
    width:8%;
}


.list-title{
    float:left;
    width:35%;
}

.list-owner{
    float:left;
    width:15%;
}

.list-date{
    float: left;
    width: 20%;
}
      

<div class="list-item">
<p>
 <input type="checkbox" class="cb">
 <div class="list-type"><img src="/images/types/{{this.type}}.png" title="{{this.type}}" /></div> 
 <div class="list-title">Title</div> 
 <div class="list-owner">Owner</div>
 <div class="list-date">16 Dec 2014</div>
</p>
 </div><br>
<div class="list-item">
<p>
 <input type="checkbox" class="cb">
 <div class="list-type"><img src="/images/types/{{this.type}}.png" title="{{this.type}}" /></div> 
 <div class="list-title">Title22</div> 
 <div class="list-owner">Owner22</div>
 <div class="list-date">16 Dec 201422</div>
</p>
 </div><br>
<div class="list-item">
<p>
 <input type="checkbox" class="cb">
 <div class="list-type"><img src="/images/types/{{this.type}}.png" title="{{this.type}}" /></div> 
 <div class="list-title">Title 333</div> 
 <div class="list-owner">Owner 333</div>
 <div class="list-date">16 Dec 2014333</div>
</p>
 </div>
      

Run codeHide result


Did it help ???

+2


source


Try CSS tables:



.list-item {
  display: table;
}
.list-item > p {
  display: table-row;
}
.list-item > p > * {
  display: table-cell;
}

      

+3


source


Try using below css:

.list-title{ margin-left: 10px; width: 200px;}
.list-owner{ margin-left: 10px; width: 40px;}
.list-date{ margin-left: 10px; width: 40px;}

      

Note . Resize the width to suit your needs.

+1


source


Tabular data: use tables.

Or, as @ioriol suggested, use CSS tables.

-2


source







All Articles