Eliminate the gaps between the columns of the table

Is there a way to eliminate the gap between the day, month, and year columns in this table?

<form action='goServlet' method='POST'>  
    <table style="width:1000px" style="text-align:center">
        <tr style="text-align:center">
            <th>City</th>
            <th>Room Type</th>
            <th colspan="3">Start Date</th>
            <th colspan="3">End Date</th>
            <th>Discount %</th>                     
        </tr>
        <c:forEach var="item" items="${discountInfo}">
            <tr style="text-align:center">
                <td>${item.hotelLocation}</td>
                 <td>${item.roomType}</td>
                 <td><select>
                        <option value="01">01</option>
                        <option value="02">02</option>
                        <option value="03">03</option>
                        <option value="04">04</option>
                        ...
                        <option value="31">31</option>
                 </select></td>
                 ...
                <td>50</td>
            </tr>
        </c:forEach>
    </table>        

</form>

Any suggestions on how to achieve this? I've tried using cellpadding="0" cellspacing="0" along with border-collapse:collapse within the <table> tag, but it hasn't made any difference.

Appreciate your assistance!

Answer №1

Your table is currently set to a width of 1000px, with "Start Date" and "End Date" spanning 3 columns. To fix this issue, consider removing the table width

<table style="width:1000px" style="text-align:center">
or adjusting the td width to a smaller value such as td {width: 10px;}

Answer №2

  • To improve responsiveness, consider removing the fixed width of the table (currently set at width = 1000px). This will prevent issues on smaller screens and eliminate the unnecessary space between columns.
  • For fields with multiple columns (such as date fields with day, month, and year), add a specific class to the first cell in each field. This class can be used to apply padding for visual separation:

<tr>
    <th>City</th>
    <th>Room Type</th>
    <th colspan="3">Start Date</th>
    <th colspan="3">End Date</th>
    <th>Discount %</th>                     
</tr>
<tr>
    <td class="firstCellInField">Sidney</td>
    <td class="firstCellInField">Single</td>
    <td class="firstCellInField"><select>
        <option value="01">01</option>
        ...
        <option value="31">31</option>
        </select></td>
    <td><select>
        <option value="01">January</option>
        ...
        <option value="12">December</option>
        </select></td>
    <td><select>
        <option value="2014">2014</option>
        ...
        <option value="2019">2019</option>                         
        </select></td>
    <td class="firstCellInField"><select>
        <option value="01">01</option>
        ...
        <option value="31">31</option>
        </select></td>
    <td><select>
        <option value="01">January</option>
        ...
        <option value="12">December</option>
        </select></td>
    <td><select>
        <option value="2014">2014</option>
        ...
        <option value="2019">2019</option>                         
        </select></td>
    <td class="firstCellInField">50</td>
</tr>

th {
    text-align:left;
}

th, td.firstCellInField {
    padding-left: 20px;
}

For a visual representation, check out this fiddle

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

Apply a style to the div element that contains a TextInput component

As a beginner in the world of React and Material UI, I am currently working with Material UI version "1.0.0-beta.17", React 15.6.2, styled-components 2.0.0, and styled-components-breakpoint 1.0.1. Within a div element, I have two TextInput fields. const ...

Click to switch CodeMirror's theme

http://jsbin.com/EzaKuXE/1/edit I've been attempting to switch the theme from default to cobalt and vice versa, toggling each time the button is clicked. However, I am facing an issue where it only switches to the new theme once and doesn't togg ...

Tips for identifying the clicked location inside an element using JavaScript?

Is there a way in JavaScript to find out the exact position of a click within an element, like its distance from the left, right, or center? I'm struggling to determine whether the clicked area is on the left, center, or right side. https://i.stack.i ...

discovering the category for the .click function

After retrieving a list of book objects from a JSON object, I am in the process of displaying them on an HTML page by creating buttons with titles. The goal is to alert the URL of the book when a button is clicked. However, I am facing an issue with access ...

Struggling to access the height attribute from a CSS file

Hey there. I'm pretty confident that the solution to my query is quite simple. So, I have a .css file with this particular code snippet: div.site { text-align:center; border:2px solid #4b6c9e; padding:1px; margin-top:10px; font-size:medi ...

What is the method for aligning an <img> to the right within a Bootstrap 4 card-body?

I am having difficulty aligning an image to the right within a Bootstrap 4 card-body. I attempted to use the float-right class, but it doesn't seem to be working. Are there any specific considerations for aligning images in a card-body? <div class ...

What are the steps to ensure that this iframe adjusts perfectly to the page in terms of both vertical and horizontal dimensions

I have a sandbox from Material UI that you can view at this link: https://codesandbox.io/s/material-demo-forked-c8e39?file=/demo.js Upon loading the page, an iframe displays some HTML content. Although the width fits perfectly, there are two vertical scro ...

Exploring the use of the map function for iterating in a stepper component of

I've been attempting to integrate Redux Form into my stepper component. However, I'm facing an issue where adding form fields results in them being displayed in all three sections. To address this, I started reviewing the code for the stepper. I ...

How can I use jQuery to automatically redirect to a different HTML page after updating a dynamic label?

When I click on a button in first.html, a function is called to update labels in second.html. However, despite being able to see second.html, I am unable to see the updated values in the labels. Can someone please advise me on how to achieve this? functi ...

After making a POST request, the `Req.body` is assigned to

This is the JavaScript code I am using: app.use(express.static(__dirname)); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); // support json encoded bodies app.get('/', function(req, res){ res.sendFile(__dirn ...

Pressing the dart key will alter the sprite's direction in a 2D game

Recently, I've been working on a Dart game where the user controls a space ship sprite using the W, A, S, and D keys. Pressing these keys will move the sprite up, left, right, and down respectively. Additionally, pressing the Space bar will launch a p ...

Strange outcomes observed with CSS Selector nth-child

When utilizing the CSS nth-child selector, I am encountering some peculiar issues. The HTML structure is as follows: <div class="block feature-callout-c" id="overview"> <div class="row"> <div class="span twelve"> ...

I desire to alter the description of an item within a separate div, specifically in a bootstrap

I used the map method to render all the images. However, I need a way to track the current image index so that I can change the item description located in another div. Alternatively, if you have any other solutions, please let me know. App.js : import Ca ...

Enable the bottom footer to expand along with the content to support a dynamically growing page

I followed a tutorial on keeping footers at the bottom of a webpage (http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page) to create a site with a fixed footer. However, I encountered an issue when there is more content than can fit ...

Issues with implementing a Bootstrap dropdown list in a Django HTML template

I'm having trouble implementing Bootstrap in my Django project's shared HTML file. The dropdown list isn't functioning properly despite trying various approaches, including using CDN and local Bootstrap files. When I click on the dropdown li ...

Ensuring User Input Integrity with JavaScript Prompt Validation

I need help with validating input from a Javascript prompt() in an external js file using HTML code. I know how to call the Javascript function and write the validation logic, but I'm unsure how to handle the prompt and user input in HTML. Do I need ...

I attempted to connect my JavaScript file to my HTML file, but unfortunately, no changes are taking place

I have created an HTML file where I am trying to pass input from it into a function located in a separate JavaScript file, and then have the data added to a SQL server. The JavaScript file works perfectly fine when run independently, but when I try to call ...

Div or box container with a CSS arrow sliced through

Is there a way to transition from a basic square menu to something more complex like this -> view image example Below is the CSS I've been using: .menu { width:50px; height:50px; display:block; background-color:red; overflow:hidden -ms-transform: ...

What is the best way to implement a required input field in Vue.js?

I need some assistance with my chat functionality. I want to prevent users from sending empty messages, so I want to make the input field required. Can you please help me with this? I have already tried adding "required='required'" to the input ...

An always-visible navigation menu

After exploring various resources related to the same topic, such as sticky navigation bars and others, I noticed that all the solutions provided involved the use of this link http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js. However, inc ...