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

Tips for inserting a page break after every item in a loop in Visualforce when generating a PDF document

I need help with rendering a VF page as PDF. The VF page iterates over a list of account records using the repeat tag. I want to apply a page break for each element in the repeat tag. The code below is working, but it has an issue - it shows an empty PDF p ...

`Enhancing the appearance of code in PHP`

I'm struggling with customizing the data pulled from the database. Can anyone provide assistance? I attempted to define $style within the while loop and assign it to $questions, but nothing is displaying on the webpage. While I have some familiarity w ...

Dart and external CSS and JS libraries and tools

As I prepare to dive into developing my very first web application, one technology that has caught my eye is Google Dart. The idea of using a new, innovative approach to web development excites me, and I am seriously considering utilizing it for my project ...

How to ensure text wraps when resizing window in CSS? The importance of responsive design

UPDATE: I finally fixed my scaling issues by setting the max-width to 760px. Thank you for the tip! However, a new problem has emerged - now my navigation scales in the small window and I want it to remain a fixed size. Hello everyone! I am currently lear ...

Troubleshooting a background image problem in a TailwindCSS configuration file

I'm having trouble getting the background image to show up correctly using tailwind.Config.Js. Even though Tailwind.Config.Js is generating the background image perfectly, when I view it in the browser, it's displaying a 404 error for the image. ...

A step-by-step guide on customizing the background color of the selected date in the MUI DatePicker

I am looking to customize the background color of selected dates in a MUI datePicker. In the image below, you can see that I want to change the blue color to a different color. Here is my code: const customStyles = makeStyles(theme => ({ datePickerC ...

Use jQuery to switch out certain text with specified HTML elements

I am looking to use jQuery in order to dynamically wrap any text that matches a specific regular expression with a particular HTML tag. For instance: <div class="content"> <div class="spamcontainer"> Eggs and spam is better than ham and spam. ...

CSS - Layering <divs> on top of clear <div>'s

Is there a method to eliminate the transparency of content/images within a <div> that is transparent? Below is the provided HTML: <div id="main-button-wrapper" class="left"> <div id="button-bg-layer" class="box-bg-layer corner ...

Guide to verifying Regular Expressions for text fields in JSP with JavaScript

Need help with validating the firstname using regex. The javascript code provided generates an error if the value length is 0, however, even after entering a correct firstname format based on the regex, it still shows 'First name invalid'. I susp ...

Angular application featuring scrolling buttons

[Apologies for any language errors] I need to create a scrollable view with scroll buttons, similar to the image below: Specifications: If the list overflows, display right/left buttons. Hide the scroll buttons if there is no overflow. Disable the le ...

Conceal the Download Button Effectively

I operate a website for playing audio files and I am looking to prevent users from downloading the sounds using the download button in the HTML audio element. Here is what I came up with: <audio src="sound.mp3" controls controlsList="nodownload">< ...

"Unveiling the invisible: Revealing hidden characters in PHP

Currently I am dealing with some code extracted from a MySQL column. Within this code are hidden characters like "\t" and "\n". I am attempting to showcase the raw code in a DIV while also making sure these hidden characters are visible. The cod ...

Obtain several dropdown menus without their items displaying beneath the correct element

I'm currently in the process of setting up multiple drop down menus within a navigation element. The issue I'm facing is that when a user hovers over the menu items, the displayed elements appear below the first item instead of the selected one. ...

What is the best way to retrieve the value of a submitted button in a jQuery form submission?

I am facing an issue with my HTML code. Here is the structure: <form method="post" id="IssueForm" action="wh_sir_insert.php"> <input name='id[]' type='checkbox' class="selectable" value='$col[8]' /> <inpu ...

Is there a way to line up these two tables or divs using a shared parent header div?

In the process of developing this webpage, I encountered a layout that resembles the following: Here is an approximation of the HTML structure: <div class="title"> <table> <tr> <td width="35%">Table 1a Head ...

Having Trouble with Form Submission Button Across Different Web Browsers

Having some trouble with my form - all fields are properly closed with tags, but when I click the submit button, nothing happens. The page is loaded with code, so here's the link for you to check it out. Unfortunately, right-click is disabled, so ple ...

Discovering the technique to display data in PHP only from the database that is specific to the authenticated user

When creating a to-do list, I want the user (not admin) to only see tasks assigned to them. This should be indicated under the assignee column with their name. https://i.stack.imgur.com/WP5C8.png However, currently the user named Lala can see not only th ...

every cell should be painted a distinct hue

I need to create a 10x10 array in JavaScript and fill each cell in the 2D array with different colors using canvas. I have managed to do this part, but now I am stuck on how to check if each cell has a different color from its neighbors. Any suggestions ...

How can I incorporate multiple JSX files into plain HTML without using npm?

I have a question regarding importing JSX files in an HTML file without using npm and directly running it with LiveServer. I have two files, index.js and app.jsx, that I want to connect within my index.html script. How can I achieve this? Code: index.html ...

Can we pause and resume the progress bar using Javascript in conjunction with animationPlayState?

Looking for a way to control a progress bar script that runs for 180 seconds and then redirects the browser? Check out the code snippet below. I've added an onclick event to test pausing the progress bar. My goal is to pause, reset, and adjust the dur ...