0

I am attempting to align the column headers on my grid with the data in my grid. I don't quite understand why the grid column sizes differ even though they use the same css class: Can someone please give me a hand:

.outer {
  width: 60%;
  height: 300px;
}

.panel {
  display: flex;
  flex-flow: column;
  width: 100%;
  height: 100%;
}

.gridpanel {
  display: grid;
  width: 100%;
  grid-gap: 0.5em 0.6em;
  padding: 2px 5px;
  box-sizing: border-box;
  grid-template-columns: 1fr 2fr 0.5fr;
}

.header {
  background-color: dodgerblue;
  border-bottom: 1px solid blue;
}
<div class=outer>
  <div class=panel>
    <div class="gridpanel header">
      <div> Telephone Type</div>
      <div> Telephone Number</div>
      <div> Action</div>
    </div>
    <div class="gridpanel">
      <input type="text" autofocus />
      <input type="text" autofocus />
      <button>Delete</button>
    </div>
  </div>
</div>

The fiddle is here: https://jsfiddle.net/btyrx4wo/5/

j08691
  • 204,283
  • 31
  • 260
  • 272
Elcid_91
  • 1,571
  • 4
  • 24
  • 50

1 Answers1

0

Width to elements, if not you can use table layout

.outer{
  width: 100%;
  height: 300px;  
}
.panel{
  display: flex;
  flex-flow: column;
  width: 100%;
  height: 100%; 
}
.gridpanel{
  display: grid;
  width: 100%;
  grid-gap: 0.5em 0.6em;
  padding: 2px 5px;
  box-sizing: border-box;  
  grid-template-columns: 1fr 2fr 0.5fr;
}
.header{
  background-color: dodgerblue;
  border-bottom: 1px solid blue;
}
<div class=outer>
  <div class=panel>
     <div class="gridpanel header">
       <div style="width:200px;"> Telephone Type</div>
        <div style="width:200px;"> Telephone Number</div>
        <div style="width:100px;"> Action</div>       
     </div>
     <div class="gridpanel">
        <input type="text" autofocus />
        <input type="text" autofocus />
        <button>Delete</button>
     </div>
  </div>
</div>
 
Umesh
  • 529
  • 5
  • 11