tbg
tbg

Reputation: 43

Book index layout style with bottom line in HTML and CSS

How can I achieve this layout in HTML & CSS ? example

Maybe with a table, but I need the center column to fill the blank space with a border-bottom (or something else)

Here is a codepen

<table class="table">
  <tbody>
    <tr>
      <td>
        <h5>Index 1</h5></td>
      <td>
        <span class="line">&nbsp;</span>
      </td>
      <td>
        Content
      </td>
    </tr>
    <tr>
      <td>
        <h5>Index 2</h5></td>
      <td>
        <span class="line"></span>
      </td>
      <td>
        Content
      </td>
    </tr>
  </tbody>
</table>

Upvotes: 2

Views: 414

Answers (2)

user6144292
user6144292

Reputation: 163

try this

<table class="table">
  <tbody>
    <tr>
      <td class="Index">
        <h5>Index 1</h5>
      </td>

      <td>
        Content
      </td>
    </tr>
    <tr>
      <td class="Index">
        <h5>Index 11</h5>
      </td>

      <td>
        Content
      </td>
    </tr>
  </tbody>
</table>

<----css----->

table {
  width: 50%;
  border-collapse: collapse;
  white-space: nowrap;
}
table h5 {
  margin: 0;
  display:inline-block;
}
td,
tr,
table {
  padding: 0;
  overflow:hidden
}

.Index::after{
  content:"";
width:100%;
  display:inline-block;
background-color:#000;
height:1px;}

Upvotes: 2

Gaurav Aggarwal
Gaurav Aggarwal

Reputation: 10177

If you are using table then you can achieve the same by following codes

table {
  width: 50%;
  border-collapse: collapse;
  white-space: nowrap;
}
table h5 {
  margin: 0;
}
td,
tr,
table {
  padding: 0;
}
td:nth-child(2) {
  border-bottom: 1px solid;
  width: 100%;
}
<table class="table">
  <tbody>
    <tr>
      <td>
        <h5>Index 1</h5>
      </td>
      <td>
        <span class="line">&nbsp;</span>
      </td>
      <td>
        Content
      </td>
    </tr>
    <tr>
      <td>
        <h5>Index 2</h5>
      </td>
      <td>
        <span class="line"></span>
      </td>
      <td>
        Content
      </td>
    </tr>
  </tbody>
</table>

Upvotes: 0

Related Questions