Tips for creating space between table columns

I am looking to enhance the spacing between columns in my table to achieve a layout similar to the reference image provided. Can you suggest any adjustments I can make to my code to achieve this look?

Reference table :

https://i.sstatic.net/xfqiR.png

Here is the current code for my table, feel free to provide suggestions on how to improve it further. Thank you.

<style>
  .styled-table {
    border-collapse: collapse;
    margin: 25px 0;
    font-size: 0.9em;
    font-family: sans-serif;
    min-width: 400px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
  }

  .styled-table thead tr {
    background-color: #6c6f7271;
    color: #000000;
    text-align: left;
  }

  .styled-table th,
  .styled-table td {
    padding: 12px 15px;
  }

  .styled-table tbody tr {
    border-bottom: 1px solid #dddddd;
  }

  .styled-table tbody tr:nth-of-type(even) {
    background-color: #8410e393;
  }
  
</style>

  <div>
    <table class="styled-table">
      <thead>
        <tr>
          <th>Name</th>
          <th>age</th>
          <th>city</th>
          <th>salary</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Ashish</td>
          <td>21</td>
          <td>Mumbai</td>
          <td>90000</td>
        </tr>
        <tr>
          <td>Yadnesh</td>
          <td>20</td>
          <td>Mumbai</td>
          <td>88000</td>
        </tr>
        <tr>
          <td>Vinit</td>
          <td>20</td>
          <td>Mumbai</td>
          <td>70000</td>
        </tr>
        <tr>
          <td>Pushkar</td>
          <td>21</td>
          <td>Mumbai</td>
          <td>84000</td>
        </tr>
        <tr>
          <td>Pushkar</td>
          <td>21</td>
          <td>Mumbai</td>
          <td>84000</td>
        </tr>
        <!-- Any additional data goes here... -->
      </tbody>
    </table>
  </div>

Answer №1

Have you thought about increasing the spacing horizontally?

<style>
  .styled-table {
    border-collapse: collapse;
    margin: 25px 0;
    font-size: 0.9em;
    font-family: sans-serif;
    min-width: 400px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
  }

  .styled-table thead tr {
    background-color: #6c6f7271;
    color: #000000;
    text-align: left;
  }

  .styled-table th,
  .styled-table td {
    padding: 12px 60px;

  }

  .styled-table tbody tr {
    border-bottom: 1px solid #dddddd;
  }

  .styled-table tbody tr:nth-of-type(even) {
    background-color: #8410e393;
  }
  
</style>

  <div>
    <table class="styled-table">
      <thead>
        <tr>
          <th>Name</th>
          <th>age</th>
          <th>city</th>
          <th>salary</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Ashish</td>
          <td>21</td>
          <td>Mumbai</td>
          <td>90000</td>
        </tr>
        <tr>
          <td>Yadnesh</td>
          <td>20</td>
          <td>Mumbai</td>
          <td>88000</td>
        </tr>
        <tr>
          <td>Vinit</td>
          <td>20</td>
          <td>Mumbai</td>
          <td>70000</td>
        </tr>
        <tr>
          <td>Pushkar</td>
          <td>21</td>
          <td>Mumbai</td>
          <td>84000</td>
        </tr>
        <tr>
          <td>Pushkar</td>
          <td>21</td>
          <td>Mumbai</td>
          <td>84000</td>
        </tr>
        <!-- and so on... -->
      </tbody>
    </table>
  </div>

Answer №2

 To increase the width to 600px, simply add this line of code:

 I made a small adjustment to the code below

   .styled-table {
    border-collapse: collapse;
    margin: 25px 0;
    font-size: 0.9em;
    font-family: sans-serif;
    min-width: 400px;
    width:600px;    //  <------ Just added this 
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
    }

  .styled-table {
    border-collapse: collapse;
    margin: 25px 0;
    font-size: 0.9em;
    font-family: sans-serif;
    min-width: 400px;
    width:600px;    //  <------ Just added this 
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
  }

  .styled-table thead tr {
    background-color: #6c6f7271;
    color: #000000;
    text-align: left;
  }

  .styled-table th,
  .styled-table td {
    padding: 12px 15px;
  }

  .styled-table tbody tr {
    border-bottom: 1px solid #dddddd;
  }

  .styled-table tbody tr:nth-of-type(even) {
    background-color: #8410e393;
  }
  <div>
    <table class="styled-table">
      <thead>
        <tr>
          <th>Name</th>
          <th>age</th>
          <th>city</th>
          <th>salary</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Ashish</td>
          <td>21</td>
          <td>Mumbai</td>
          <td>90000</td>
        </tr>
        <tr>
          <td>Yadnesh</td>
          <td>20</td>
          <td>Mumbai</td>
          <td>88000</td>
        </tr>
        <tr>
          <td>Vinit</td>
          <td>20</td>
          <td>Mumbai</td>
          <td>70000</td>
        </tr>
        <tr>
          <td>Pushkar</td>
          <td>21</td>
          <td>Mumbai</td>
          <td>84000</td>
        </tr>
        <tr>
          <td>Pushkar</td>
          <td>21</td>
          <td>Mumbai</td>
          <td>84000</td>
        </tr>
        <!-- and so on... -->
      </tbody>
    </table>
  </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

What is the method for encoding and decoding a query string within an HTML object tag?

Within my code, I am utilizing an object tag that utilizes a data attribute to call a servlet. When passing a parameter to the URL, if the value is not in English but instead Arabic, for example, the value appears distorted when retrieved in the specified ...

The target element is out of reach for the Puppeteer selector

When trying to extract the source of multiple images, I encountered an issue with the selectors not working properly. It seems like the elements are fake or not actually present on the page. Every page contains one of the desired elements (the main image) ...

New space is formed as the input box gains focus on the signin field

I'm currently working on a sign-in page and implementing JQuery. Everything seems to be functioning properly except for a minor issue. The problem is that when the password field gains focus, it creates extra space in IE 8 and later versions only. Th ...

Spacing between navigation items

After working on my navigation menu locally, I noticed that when I uploaded it online, some changes didn't take effect on Chrome and the design on Firefox was different from what I intended. I'm not sure what I might be doing wrong here. Here is ...

AngularJS allows us to easily include the route provider templateUrl path in the view div, making

I have the following route provider setup: $routeProvider .when('/', { templateUrl: '/slapppoc/Style Library/TAC/Views/tarification/home.html', controller: 'homeController' /* resolve: { // This f ...

Unable to adjust the margin-bottom attribute in CSS

Currently, I'm in the process of developing a website and attempting to build the client-side without using any frameworks. However, for some reason, I am facing difficulty in changing the margin-bottom property. My goal is to create space between the ...

Is there a way to reset a value back to its original user agent default?

When utilizing the initial value, I have the ability to designate an element's CSS property to its initial value per the specification. However, there are instances where I may prefer to set a CSS property to its initial user agent value instead. Fo ...

Modify the color of the chosen option in the dropdown menu without affecting the rest of the options

I am facing an issue with dynamic drop down lists in my HTML content. The requirement is to change the color of the selected option to dark red if the option is "success". I have implemented a jQuery function for this purpose. HTML: <select class="rea ...

Determine who the creator of the clicked div is

I'm sorry if my explanation is a bit difficult to comprehend. Here is the code snippet in question: names.push(newName); var strName = newName; var newName = document.createElement('p') newName.setAttribute('id', newName); documen ...

Adding styles to specific child nodes within a p-tree component in PrimeNG

Starting off with a demonstration example: Check out this StackBlitz for primeng p-tree. I am utilizing primeng to construct a structure for polls and answers using p-tree. The hierarchy is as follows: Participants --> Polls --> Questions --& ...

The alignment of elements on the right and left sides is not functioning as intended

I've been facing an issue with the alignment of my floats on my brand new website www.unicmedia.nl/case/oranje. Surprisingly, they seem to work fine in IE this time, but Firefox and Chrome are completely out of sync. Despite trying numerous solutions ...

The functionality of the Angular JS Controller is hampered when integrated with a .js file

Having just started using Angular JS, I encountered an issue with a simple example I was working on. I wrote a script.js file with the following code:- var myApp = angular.module("myModule", []).controller("myController", function ($scope) { $scope.m ...

Obtaining numerous distinct array elements

I have created a form with checkboxes for users to select options. <input type="checkbox" name="rights[]" value="1" class="a"> A <input type="checkbox" name="rights[]" value="2" class="b"> B <input type="checkbox" name="rights[]" value="3" ...

The label element in a CSS form is not displaying correctly

After clicking submit on the form located at this link: I am experiencing an issue where the validation messages are not displaying as intended. I would like them to appear next to the input elements, inline with the form. I suspect that there may be a p ...

A guide to adjusting the size of a mat-button using an svg mat-icon

I have PrimeNg and Angular Materials buttons on the same td. I am attempting to resize my mat-buttons to match the size of my pButtons but they are not adjusting properly. Should I consider using a different type of button with my icon? HTML <button ma ...

Is it possible for links to remain clickable even if they pass underneath a div

I have implemented a shadow using a div element to cover some content beneath it. However, I am facing an issue where the div that is under the shadow cannot be interacted with. Is there any solution to this problem? Thank you ...

Navigating the art of employing different fonts for a website

I am looking to incorporate the trainway font into my website, but I'm concerned that the user may not have it installed on their device. Is there a way to showcase text in a specific font without requiring the user to download and install it? Thank ...

Ways to emphasize text in a h2 header without affecting other elements

One particular HTML block is causing me some trouble: <h2><span class="numbers">1.1 </span>header text</h2> It's important to note that I did not write this HTML code, so my options for changing it are limited. Howev ...

A completely css-based interpretation of google images

I am in the process of trying to recreate the layout found in Google Photos and stumbled upon this intriguing page https://github.com/xieranmaya/blog/issues/6 . I am particularly interested in the final result of the project, which can be viewed here: . U ...

How to incorporate multiple fonts into spark RichText using CSS - Flex edition!

I'm currently facing a challenge with embedding multiple fonts in a spark RichText component. Specifically, I am unsure about how to proceed with displaying bold font using <b> tags in HTML. The font I am working with has separate regular and bo ...