0

I have the following list structure:

<ul class="clientlist">
    <li class="clientname">
        <span class="id">IDxxx</span><span class="name">Hugo</span><span class='clientcount'>15</span>
        <ul class="fbllist">
            <li class="fbladdress">
                <span class="address">[email protected]</span><span class="fblcount">15</span>
                <ul class="iplist">
                    <li class="ipstatus">
                        <span class="statustext">active</span><span class="statuscount">15</span>
                    </li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

which is nicely displayed, thanks to CSS like:

Of course there are several Elements like this, so a list may look like this:

Now I'm trying to find a way to format this more "table like" and tried this css

ul {
  display: table;
}

li {
  display: table-row;
}

li span {
  display: table-cell;
}

span.ipcount,
span.clientcount,
span.statuscount {
  text-align: right;
}
<ul class="clientlist">
  <li class="clientname">
    <span class="id">IDxxx</span><span class="name">Hugo</span><span class='clientcount'>15</span>
    <ul class="fbllist">
      <li class="fbladdress">
        <span class="address">[email protected]</span><span class="fblcount">15</span>
        <ul class="iplist">
          <li class="ipstatus">
            <span class="statustext">active</span><span class="statuscount">15</span>
          </li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

Unfortunately, due to the fact that the uls are nested within lis, the result is not quite what I hoped for. All the "sub-tables" (the nested uls) are shown at the very right end of each "row" (li).

Is there any way I can change it so that each "sub-table" is displayed like being in a new row without changing the structure?

Update: This is what it looks like when I add borders to the tables (black) and cells (green) enter image description here

I hoped for something like this: enter image description here

3
  • 2
    What could possibly be your motivation for all that? Why not just use a modern grid (or a table)? What's the benefit of using list markup? Commented Nov 18, 2021 at 13:39
  • 1
    what is it suppose to look alike ? display:contents allows you to make subchild be direct child without touching the markup. You can use either table/flex or grid , whatever suits your behavior needs. From your bit of HTML, is that supposed to be a row, 2 rows, 3 rows, something else ? Commented Nov 18, 2021 at 13:43
  • Simply assume, isherwood that there is no benefit in using list markup, but that it is simply there. G-Cyrillus I've added two screenshots. Commented Nov 18, 2021 at 14:31

2 Answers 2

2

You can make a mix of table/grid and contents display to achieve something mostly alike your goal:

example

.clientlist,
li,
span {
  box-shadow: 0 0 0 1px;/* or border */
}

.clientlist {
  display: table;
}

.clientname {
  display: grid;
  grid-template-columns: 1fr auto auto;
}

.ipstatus {
  display: contents;
}

.fbladdress,
.iplist {
  display: grid;
  grid-template-columns: 1fr auto
}
<ul class="clientlist">
  <li class="clientname">
    <span class="id">IDxxx1</span><span class="name">Hugo</span><span class='clientcount'>15</span>
    <ul class="fbllist">
      <li class="fbladdress">
        <span class="address">[email protected]</span><span class="fblcount">15</span>
        <ul class="iplist">
          <li class="ipstatus">
            <span class="statustext">active</span><span class="statuscount">15</span>
          </li>
        </ul>
      </li>
    </ul>
  </li>
  <li class="clientname">
    <span class="id">IDxxx2</span><span class="name">Hugo2</span><span class='clientcount'>15</span>
    <ul class="fbllist">
      <li class="fbladdress">
        <span class="address">[email protected]</span><span class="fblcount">14</span>
        <ul class="iplist">
          <li class="ipstatus">
            <span class="statustext">active</span><span class="statuscount">13</span>
          </li>
          <li class="ipstatus">
            <span class="statustext">monitored</span><span class="statuscount">1</span>
          </li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks G-Cyrillus. That gives me something to play with. I never yet saw display: grid nor 1fr. Something to learn.
0

Thanks to G-Cyrillus I now have this CSS as a solution.

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
.clientlist {
    display: grid;
    grid-template-columns: 100%;
    row-gap: 0.5em;
}
.clientname {
    display: grid;
    grid-template-columns: 6em 2em 2em min(10em) 6em;
    grid-template-areas: 
        "id name name name count"
        ".. fbl  fbl  fbl  fbl"
    ;
    justify-items: start;
}
.id {
    grid-area: id;
}
.name {
    grid-area: name;
}
.clientcount {
    grid-area: count;
    justify-self: end;
}
.fbllist {
    grid-area: fbl;
}
.fbladdress {
    display: grid;
    grid-template-columns: 2em 2em min(10em) 6em;
    grid-template-areas: 
        ". address address fblcount"
        ". status  status  status"
    ;
    justify-items: start;
}
.address {
    grid-area: address;
}
.fblcount {
    grid-area: fblcount;
    justify-self: end;
}
.iplist {
    grid-area: status;
}
.ipstatus {
    display: grid;
    grid-template-columns: 2em min(10em) 6em;
    grid-template-areas: 
        ". statustext statuscount"
    ;
    justify-items: start;
}
.statustext {
    grid-area: statustext;
}
.statuscount {
    grid-area: statuscount;
    justify-self: end;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.