Are there any alternative methods to elegantly organize a form within a table other than the one showcased here? My form consists of varying numbers of

Within the initial row, I have incorporated four columns, while rows 2-4 contain two columns each to enhance the formatting. I am seeking a more elegant approach to address this issue and avoid triggering the validation warning. This task pertains to a school project, and while it is not overly complex, I aim to execute it accurately.

<div>
            <h2>Personal Information</h2>
            <form method="post">
                <table class = "center">
                    <tr>
                        <td style = "text-align:right;">First Name:</td>
                        <td>
                            <input name = "fname" type = "text"
                                size = "25" maxlength = "20"
                                required autofocus>
                        </td>

                        <td>Last Name:</td>
                        <td> 
                            <input name = "lname" type = "text"
                                size = "25" maxlength = "20">
                        </td>
                    </tr>

                    <tr>
                        <td>Email Address:</td>
                        <td>
                            <input name = "email" type = "email"
                                placeholder = "e.g., <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fdb7929593b99298bd98859c908d9198d39e9290">[email protected]</a>"
                                size = "25"
                                required title = "Must be a valid email address">
                        </td>
                    </tr>

                    <tr>
                        <td style = "text-align:right;">Gender:</td>
                        <td style = "text-align:left">
                            <label>Male</label>
                                <input name = "gender" type = "radio"
                                    value = "Male">     
                            <label>Female</label>                   
                                <input name = "gender" type = "radio"
                                    value = "Female">
                        </td>
                    </tr>

                    <tr>
                        <td style = "text-align:right;">Age Group:</td>
                        <td style = "text-align:left">

                            <label>Under 21</label>
                                <input name = "under" type = "checkbox"
                                    value = "under">
                            <label>21 - 40</label>
                                <input name = "to" type = "checkbox"
                                    value = "to">
                            <label>Over 40</label>
                                <input name = "over" type = "checkbox"
                                    value = "over">
                        </td>
                    </tr>
                </table>
            </form>
        </div>

Answer №1

When dealing with rows that have only 2 columns, you can utilize the 'colspan' attribute to allow a cell to span across multiple columns, ensuring everything aligns properly.

For example:

<tr>
 <td>Username:</td>
 <td colspan="3">
  <input name = "username" type = "text" placeholder = "Enter your username" size = "20" required title = "Please enter your username">
 </td>
</tr>

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

Unable to access the website's source code

It's frustrating when I can't view the source code of certain websites, such as this one: . When I try to right-click and select "View Source", only a portion of the code is displayed, which isn't the proper source code for the page. Alth ...

Is there a way to eliminate the gap between two horizontal rule tags?

What causes the space between two <hr> tags to remain? Despite setting the width of the <hr> tags to 49%, there is still a gap between them. How can this space be removed from the <hr> tags? Shown below is the HTML and CSS code: *{mar ...

Requesting HTML content from a PHP file using JQuery Ajax callback

For an ajax request, I am entering a name in an input box to search for data from a database. Everything is functioning properly. <script> $(document).ready(function(){ $('input#name-submit').on('click', function() { ...

Difficulty arises in designing a tableless layout due to the issue of auto

Wondering why my page is not expanding with its content? Check out my demo on Fiddle http://jsfiddle.net/msas3/. The light blue area should determine the overall height of the page. ...

What is the best way to set up a condition that only runs if an element does not contain a certain class, such as "active"?

Click here for the picture I have a list of items: a, b, c, d, e, f. Whenever I click on item b, it becomes active and the other elements lose the "active" class. When an element has the "active" class, I want the background to change accordingly. If it ...

Employing conditional statements in conjunction with styled components

Is there a way to style my PaymentBtn with the main styled Button but only apply the hover effect when the isLoading prop is activated, without changing anything else? I want the styling to remain the same except for the hover effect. Basic button export ...

How can you add draggable functionality to a Bootstrap dropdown menu?

My custom bootstrap dropdown design <div class="dropdown"> <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> Dropdown <span cla ...

Issue with displaying Facebook meta image when sharing

Having trouble displaying a custom Facebook image on the share button. I am testing from localhost, could that be the issue (unable to test in production yet)? The image address is sourced from the web and I have tried various options. <meta property=" ...

What is the reasoning behind the "open in a new tab" function triggering a GET request?

Check out this HTML tag: <a href="#" id="navBar_navBarInput_3_subNavDropdownInput_0_subNavLinkInput_0" onclick="redirectPost(4,'EntryData.aspx');">My Cool Link</a> The Javascript function "redirectPost" function redirectPost(id, ur ...

What could be causing my inline-block divs to not line up correctly?

Presented below is the code snippet of my HTML: .classWrap { text-align: center; } .classInd { display: inline-block; height: 200px; width: 200px; margin: 20px; border: 2px solid #FFF202; border-radius: 10%; box-shadow: 0 0 15px 0 #FFF2 ...

Combining CSS and JS files for accordion list - experiencing issues when used separately

Recently, I've been trying to create an accordion list and stumbled upon some code (HTML, CSS, and JS) on www.w3schools.com. When I have the code all in one document and run it as a single .html file, everything works perfectly. However, when I split ...

Firebase issue: The function ref.once is throwing an Uncaught TypeError and is not recognized

I am attempting to utilize Firebase for both uploading a file and storing it in my database simultaneously. I want to track the number of uploads so that I can rename each file uniquely. While I have successfully uploaded and stored a copy in the database, ...

Showcasing an image stored in an HTML file on a Vue.js webpage

I'm currently facing an issue with displaying a local image saved in an HTML file on my Vue.js page. I attempted to store the content of the HTML file into a variable using the code below: computed: { compiledHtml: function() { return this.a ...

Pass the values of both buttons to a different page using PHP

I am currently developing a system for a hospital. The data is sourced from an array and I need to pass the values from two buttons to another page. For example, on the initial page: 1 xyz First 2017-04-08 11:35:00 body checkup Generate Presc ...

What is the best way to align the main navigation at the center of

Even though I have utilized text-align: center, the style of .main-nav did not change. What is the most effective way to center this navigation menu? /***** Navigation *****/ .main-nav { font-family: 'Lato', Helvetica, Arial, sans-serif; f ...

Incorporating FaceBook into a PhoneGap Application

Currently, I am working on integrating Facebook into my phonegap/cordova application. To guide me through the process, I am using the resources provided in this link: https://github.com/davejohnson/phonegap-plugin-facebook-connect/ Even though I have bee ...

disable border-collapse styling in ASP.NET DataList

Currently, I am new to the world of ASP.NET and I am facing a challenge in styling a DataList. Lately, I have developed a fondness for rounded corners on borders, and I am attempting to incorporate this effect into all my pages by implementing it across al ...

Angular and HTML calendar picker

Is there a way to display a date in an HTML input type="date based on a variable stored in my ts file? The variable ScreenDate is defined in my ts file. <input type="date" [(ngModel)]="ScreenDate"> I tried the above code but it did not work as exp ...

Steps for transforming div content into an image

My goal is to save an image into my local storage for future use. Currently, I have a div with some content inside. I have attempted to use canvas2Image methods without success. Here is my code: $(document).ready(function () { alert("hello"); va ...

Is it possible to embed HTML within standard PHP without using alternative methods?

Is it possible to embed HTML inside a PHP "if" statement? The top-rated answer in this thread on Stack Overflow discusses using alternative if style. While other answers suggest that it also works with normal if statements, the question remains: is this a ...