Border table row that contains table header and table section

I'm currently working on my final project in PHP and JS and could use some assistance with the HTML and CSS design.

Specifically, I need help with two things related to my sign-up form:

  1. I would like the entire row (tr) containing th tags to have a border, instead of just each individual th element having a border.

  2. I want to divide the table into sections and style each section using different CSS code.

Can anyone provide guidance on how to achieve this?

Here is the HTML code for my form:

<body>
    <form>
        <table id="t">
            <tr>
                <th>Basic info</th>
                <th>Contact info</th>
                <th>About me</th>


            </tr>

            <tr>
                <td><input placeholder="First name"></td>
                <td><input placeholder="Phone"></td>
                <td rowspan="3"><textarea rows="8" placeholder="About me"></textarea></td>
            </tr>

            <tr>
                <td><input placeholder="Last name"></td>
                <td><input placeholder="Area"></td>
            </tr>

            <tr>
                <td><input placeholder="Degree"></td>
                <td><input placeholder="Email"></td>
            </tr>

            <tr><th colspan="2">Social networks</th></tr>
            <tr>
                <td><input row placeholder="Facebook link"></td>
                <td><input row placeholder="Website link"></td>
            </tr>  
            <tr>
                <td><input row placeholder="Twitter link"></td>
                <td><input row placeholder="Medium link"></td>
            </tr>
            <tr>
                <td><input row placeholder="Instagram link"></td>
                <td><input row placeholder="Google link"></td>
            </tr>

            <tr><td colspan="2"><button type="submit">Submit</button></td></tr>

        </table>
    </form>
</body>

This is the CSS I am using:

table{
    margin: 16px;
    text-align: center;
}
td{
    padding: 10px;
    justify-content: space-between;
}
#t textarea{
   width: 100%;
   height: 100%;
}
tr>th{
    margin-top: 10px;
    border: 1px solid red;
}

Answer №1

When it comes to tables, tr elements can only have borders if the table has a style of border-collapse:collapse.

In addition, rows can be placed within <thead>, <tbody>, and <tfoot> sections for separate styling.

It might be possible to have multiple <tbody> sections and target them using nth-of-type, but further investigation is needed.

Key differences highlighted below:

  • Including thead, tbody, tfoot tags in the HTML structure
  • Styling tbody as an example
  • Applying border-collapse:collapse to the table
  • Styling tr elements within the first row

table {
  margin: 16px;
  text-align: center;
  border-collapse: collapse;
}

td {
  padding: 10px;
  justify-content: space-between;
}

#t textarea {
  width: 100%;
  height: 100%;
}

tbody {
  font-style: italic;
}
<form>
  <table id="t">
    <thead>
      <tr style="border:solid 1px">
        <th>Basic info</th>
        <th>Contact info</th>
        <th>About me</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>
          <input placeholder="First name">
        </td>
        <td>
          <input placeholder="Phone">
        </td>
        <td rowspan="3">
          <textarea rows="8" placeholder="About me"></textarea>
        </td>
      </tr>
      <tr>
        <td>
          <input placeholder="Last name">
        </td>
        <td>
          <input placeholder="Area">
        </td>
      </tr>
      <tr>
        <td>
          <input placeholder="Degree">
        </td>
        <td>
          <input placeholder="Email">
        </td>
      </tr>
      <tr>
        <th colspan="2">Social networks</th>
      </tr>
      <tr>
        <td>
          <input row placeholder="Facebook link">
        </td>
        <td>
          <input row placeholder="Website link">
        </td>
      </tr>
      <tr>
        <td>
          <input row placeholder="Twitter link">
        </td>
        <td>
          <input row placeholder="Medium link">
        </td>
      </tr>
      <tr>
        <td>
          <input row placeholder="Instagram link">
        </td>
        <td>
          <input row placeholder="Google link">
        </td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <td colspan="2">
          <button type="submit">Send</button>
        </td>
      </tr>
    </tfoot>

  </table>
</form>

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

having each individual div function on its own accord

Is there a more efficient way to make HTML and CSS function independently without duplicating the code multiple times and changing IDs or class names? Currently, only the top male and female button works when clicked. I am looking for a CSS-only solution t ...

Tips for extracting data from an array containing objects with IDs and values such as [{"id":"3","value":"12345"},{"id":"4","value":"ABCDEFG1"},{"id":"5","value":"12"

<?php $temp_hsn= getPart($d->product_id)->custom_field; ?> <td class="text-Left cname"><?php echo $temp_hsn; ?></td> The code above retrieves the following values: [{"id":"3","value":& ...

Unable to extract string using JavaScript function

When dynamically generating table rows (buttons) using JS-Ajax, I am facing an issue. The removeProduct function alerts when a numeric value is parsed, but it does not alert for a string. Can anyone assist me in resolving this problem? The problem lies in ...

The DXTreeview feature in AngularJS restricts the expansion of branches

My MVC5 project contains an Index.aspx file, but when I run it in VS2013, only the top branches of the tree are visible without any option to expand them. https://i.sstatic.net/0FWUB.png Resharper confirms that my references are correct. Being new to HT ...

Angular 9: The instantiation of cyclic dependencies is not allowed

After transitioning from Angular 8 to Angular 9, I encountered an issue with a previously functioning HTTP communication service. The error message now reads: Error: Cannot instantiate cyclic dependency! HttpService at throwCyclicDependencyError (core ...

How can I prevent duplicate IDs when submitting a form through AJAX within a while loop?

While submitting a form using Ajax within a while loop, I encountered an issue where the same form ID is being used multiple times due to the loop. As a result, the form only submits once. I believe that I need to generate a unique ID for each iteration of ...

Having difficulty retrieving the value of a form using javascript

I've been struggling to retrieve the value of a form using JavaScript, but for some reason it keeps coming up as undefined, almost as if the input doesn't exist. Here's the HTML snippet: %@ Language="VBScript" CodePage=65001 %> ... Th ...

Image displayed in tooltip when hovering over

I have been experimenting with displaying an image in a tooltip when hovering over it. I came across a fantastic solution that suits my needs: Codepen CSS: @import "compass"; * { box-sizing: border-box; } .tooltip { position: relative; border-bo ...

Troubleshooting the Ineffectiveness of Setting the CSS Top Value with jQuery

I need to center text vertically within a DIV without using fixed pixel heights, only percentages. Here's my current setup: <div style="position:relative; width: 100%; height: 100%;"> <img src="images/thumb-member-placeholder.gif" alt="" ...

Arrange a group of users in the middle

Looking for some help with this specific code snippet .selection_user { display: block; background-color: #2D2C31; text-align: center; line-height: 75px; } <div class="select_user_menu"> <div class="selection_user">User1</div> ...

Is there a way to lower the position of the main image slightly?

Is there a way to adjust the positioning of the featured image so that it lines up better with the title? Check out this page on AnyGeeks This is the code snippet responsible for setting the image. <div class="container"> <div class="jumbotron j ...

By setting up a keydown event listener, I am unable to inspect HTML elements by using the F-12 key shortcut in Chrome

Recently, I encountered an issue where adding a keydown event listener in my JavaScript code prevented F-12 from working properly. window.addEventListener("keydown", function (event) { if (event.defaultPrevented){ retu ...

Unable to resize tables in IE when using CSS Flex layout

Having a bit of trouble with the flex layout. I've put together a FIDDLE project where when resizing the output box, table cells will align one to one beneath each other. It seems to work fine in Chrome and Firefox but not in IE when using table eleme ...

Steps to utilize jQuery Masonry Plugin for organizing images

Struggling to put together a straightforward image gallery that can accommodate images of different sizes, I stumbled upon masonry in my quest for a plugin that could help with that. After attempting to create a prototype of this idea using a masonry empt ...

MUI Step Indicator Icon is not visible

I'm having trouble getting the MUI Stepper Component to display Icons within each step node. Despite following the sample code provided by MUI, my implementation only shows a blank screen instead of the desired look. The desired appearance includes i ...

"Scrolling with Bootstrap Scroll Spy is causing incorrect sections to be

Can anyone help me with my issue regarding Bootstrap scrollspy settings? It seems to be highlighting the wrong div id, always the last one. Here is the code snippet: Content: <body style="heigt: 100%" data-spy="scroll" data-target="#side-menu"> ...

A chosen class containing a nested class that utilizes the makeStyles function

Can someone explain how to target the 'element' when the root is selected? Here is the makeStyles code snippet: const useStyles = makeStyles(theme => ({ root:{ '&.selected': { } }, element: { } }) And h ...

Highcharts is not displaying the background image

As a vital part of this large-scale web-service based application, my role is to integrate graph legends onto the dynamically generated graphs. Upon joining the project, I encountered an error message when attempting to load images using incorrect paths. ...

JQuery Ajax fails to retrieve variables from an external PHP file

I have a code snippet that retrieves data from a form and sends it to form.php for processing. The form.php file then echoes out the variables (Fullname: $fullname Email: $email Link: $link Instructions: $instr) which are expected to be displayed in #succe ...

The event listener for a button click is triggered just a single time

There seems to be an issue with the click listener not firing after the first time in my class where I have multiple buttons for selecting a number. I've created a simplified version on CodePen (https://codepen.io/jasonws/pen/qBZeMMB) to showcase the ...