Alignment of columns within an HTML grid

I can't seem to figure out why my grid column headers are not aligning properly with the data in the grid. It's puzzling that they have the same CSS class but different sizes. Can someone please help me with this:

.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>

Here is the link to the fiddle: https://jsfiddle.net/btyrx4wo/5/

Answer №1

Adjusting the width of elements, or alternatively using a 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>
 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

CSS - How to specify a class within an id using syntax

How can I target a specific tag within an ID using the class name in selector syntax? For example, how can I make the inner "li" turn red in the code snippet below? <html> <head> <style type="text/css"> #navigation li ...

The issue of incomplete post content display on WordPress pages persists despite making modifications to the style.css file

click here for image descriptionI attempted to make some adjustments in the style.css file but encountered a problem. Now, all the posts on the site are displaying "[...]" after a brief and unformatted snippet of content. Any assistance would be greatly ...

What is the reason that a <button> tag is unable to include a <div> element within it?

While developing our company website, we encountered a challenge with a JavaScript library failing to replace a certain element. In an attempt to troubleshoot, we ran our HTML code through the W3C validator and discovered that nesting a <div> tag wit ...

Loading an empty CSS file in Node.js

Just starting out with node.js, and I could really use some help with a small css and image issue that I'm facing. I've streamlined my html and .js for clarity. Despite trying everything, the css and image just won't load. My form and server ...

What is the best way to conceal an unordered list menu?

Trying to create a menu using ul HTML, but encountering an issue. When the website is opened, the menu shows up by default, whereas I only want it to appear when a mouse hovers over it. Even after attempting to change the CSS class, the desired functionali ...

Is there a way to ensure that a div automatically moves below the main div when it reaches its full length?

I am facing an issue with a foreach statement in jQuery where I am generating Bootstrap cards for each product in a list. The problem arises when attempting to create multiple cards in a row, as the width of the cards becomes too small for the content. I ...

Show Text When Clicking Within Separate DIVs

I have a set of three divs. One contains a Twitter icon, another holds a LinkedIn icon, and the last one is designated for displaying text upon clicking. My goal is to click on the Twitter icon and have corresponding text appear in the third div. Then, if ...

What can be done to prevent the aspect ratio from being altered?

I am working on creating a parallax effect using a background image that is set to a width of 100% and a height of 700px. I have set the image to have a fixed attachment, but the problem arises when I change the size of the browser window - the picture los ...

Resource loading unsuccessful: server returned a 405 status code, indicating method not permitted

An error occurs when attempting to send an email using PHP. Failed to load resource: the server returned a 405 (Method Not Allowed) status for sendmail.php This is the form: <form action="sendmail.php" method="post" id="contactform" > <div ...

How can you display Unicode characters within an HTML input element with type=submit value?

I am having trouble displaying a right facing triangle character after the main text on a form button based on a designer mockup. The code snippet causing issues is as follows: <input type="submit" value="Add to basket &#9654;" /> The desir ...

The focus is on the last row that was selected

I've noticed that when I check and select a row in ui-grid, only the last selected row is focused with a background color. Should all rows be automatically painted by default? Thank you. ...

Troubleshooting: Issues with jQuery animate() not functioning properly when adjusting CSS

Currently, I am experimenting with jQuery's .animate() function to change the background of a div when it is scrolled more than 100 pixels down a page. Previously, I had successfully used .css() for this purpose. JS: $(window).scroll(function () { ...

What is the best way to retrieve a style property from a <style> tag using JavaScript?

Is there a way to retrieve CSS properties set in the <style> tag in JavaScript, rather than just those set in the element's style attribute? For example: <style> div{background:red;} </style> How can I access these styles, such ...

What are the implications of storing data on the browser in the form of a JavaScript array?

Below is the code I have written: var back_arr = [], forward_arr = [], i = 1; $('button').on('click', function(){ var new_value = $('input').val(), old_value = $('.content').html(); i = i + 1; ...

Add a plethora of images to the canvas

Just starting out with Fabric.js and trying to figure out how to draw a picture on the canvas after a drop event. I managed to do it once, but am struggling with inserting more pictures onto the canvas (each new drop event replaces the previous picture). ...

Unusual behavior observed in Angular 2 when handling button click events

In my .ts file, there are two straightforward methods: editLocation(index) {} deleteLocation(index) { this.locations.splice(index, 1); } The corresponding HTML triggers these methods when buttons are clicked: <button (click)="editLocation(i)" ...

SQL Server database is showing question marks instead of HTML symbols

Recently, I observed that special HTML symbols like: ★ are appearing as question marks in my database records. I have set the type of the field as varchar and am utilizing Microsoft SQL 2008 for my database management. Is there a solution to this symbo ...

Removing a row from a table does not delete it completely

Disclaimer: While I am aware of SQL Injection, my main focus is on getting the function completed. I'm having an issue with my delete button not removing the row from my SQL table. products-one-time.php https://i.sstatic.net/gxPOu.png This is the o ...

What is the best method to change the value of a nearby TD text box?

I am currently developing a shopping cart application that requires me to update product screens based on users' previous orders stored as local JSON data. The product screen is built using JSON returned from the server. My goal now is to automatical ...

Discovering the correct element and typing for an HTML attribute through JavaScript

We are currently working on test automation and I am looking for a way to identify the Element and Type associated with it within an html (Data-qa) attribute. For example, when looping through, the Element is identified as input and the type is radio. < ...