HTML table with two rows of cell pairs

Is it possible to achieve the layout shown in this screenshot using an HTML table?

I am aware that I can use <div> for this, but I would prefer to maintain the table formatting.

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

Answer №1

Here is the solution you requested. Please note that it's not recommended to structure your HTML in this way (moving a table cell to the next row).

*{
    margin: 0;
    padding: 0;
}

table{
    width: 100%;
    border: 1px solid red;
    padding: 5px;
}

tr{
    border: 1px solid blue;
    padding: 5px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
}

td{
    height: 50px;
    flex-basis: 24%;
    border: 1px solid green;
    margin: 5px;
    box-sizing: border-box;
}

td:last-child{
    flex-basis: 100%;
}
<table>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
</table>

Answer №2

When it comes to tables, cells do not wrap within a row, necessitating the use of a new row. In this new row, the table cell can span across other columns as needed.

Tables are best suited for displaying tabular data with correlated rows and columns. If your intention is not related to tabular data, such as layout design, it would be more appropriate to utilize alternative methods like Flexbox or grid based on the specific use case.

td {
  border: 1px solid;
  text-align: center;
  padding: .25em;
}
<table>
  <caption>It's important to include a caption for accessibility purposes.</caption>
  <tbody>
    <tr>
      <td>1</td>
      <td>2</td>
      <td>3</td>
      <td>4</td>
    </tr>
    <tr>
      <td colspan="4">This cell spans all 4 columns.</td>
    </tr>
  </tbody>
<table>

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

Building a drop down menu with HTML and CSS: a step-by-step guide

Looking for a way to create a dropdown menu for the list item with the id "gameDesignPage" in my HTML structure: <div class="MenuContainer"> <div class="Menu"> <div class="MenuContents"> <ul> ...

Matching an apostrophe in an AutoHotkey script using regex

My autohotkey script is designed to search for a word in a bilingual dictionary when I double click on any word within a webpage. However, I am facing an issue where the script also copies the characters preceding the apostrophe when clicking on words like ...

What is the best way to implement a sliding menu when clicked using HTML and CSS?

In my HTML page, there is a side menu bar displaying a list of dashboards using Django. I want this left-side menu to show only partially when logged in and fully expand after clicking on it. The HTML code snippet for the sidebar looks like: <div cl ...

What is the best way to make an image expand when clicked, align it in the center of the webpage, and have it return to its original position with just one more click by utilizing

Currently, this is the code I am working with. The JavaScript functionality is working well, however, there seems to be an issue where the image does not return to its original size on a second click. Additionally, I am having trouble getting the CSS to ce ...

Stop the Enter key from functioning as a mouse click

Whenever an element is focused on and a mouse click action can be triggered, I've observed that the Enter key functions as if you're clicking the mouse left button. This behavior is causing conflicts in other parts of my code, so I need to find a ...

What is the best way to arrange 4 divs with 2 on each line?

Consider the divs provided below: <body> <div id="f1">{{ f1|safe }}</div> <div id="f2">{{ f2|safe }}</div> <div id="f3">{{ f3|safe }}</div> <div id="f4"> ...

The component's width appears to be constrained by the use of display flex

I am currently working on a reactjs application that includes a header and another component. Initially, everything looks fine, but when I apply display: flex to their div, it seems to reduce the width of the header. Here are some images showing the issue: ...

Enhancing Your Website with Interactive Highlighting Tags

Looking at the following html: Let's see if we can <highlight data-id="10" data-comment="1"> focus on this part only </highlight> and ignore the rest My goal is to emphasize only the highlight section. I know how to emphasize a span ...

Full replacement of a cell within an HTML table

I have a scenario like the following: <table id="myTable"> <tr> <td class="1">cell 1</td> <td class="2">cell 2</td> </tr> <tr> <td class="3">cell 3</td> &l ...

Issue with CSS animation not maintaining its current position

After dedicating two months to learning CSS, I encountered a challenge with animation. Despite setting my code to finish at lime, the animation completes and the div reverts back to red. @keyframes example{ from{background-color: red} to{backgro ...

The fixed table header is misaligned with the body columns' width

I was looking for a way to add a vertical scrollbar to my table, and I ended up wrapping the entire table in a div. The result was that the table head was fixed in position. Is there a simpler method to include a scrollbar in a table without affecting the ...

Is there a way to restrict form choices depending on the previous entry, while also keeping all fields, including file selections, filled out upon submission?

Currently, I have a form set up as follows: <form name="estimate" action="live_preview.php" method="post"enctype="multipart/form-data"> <label for="file">Upload File 1:</label> <input type="file" name="file" id="file"/> ...

Determining the exact position of an image with resizeMode set to 'contain' in React Native

I am currently developing an object detection app using React Native. The process involves sending an image to the Google Vision API, which then returns a JSON file containing coordinates and sizes of objects detected within the image. My goal is to draw r ...

Tips for implementing page-break-after:always within a bootstrap row?

I have a bootstrap row with a set of divs inside like this: @media print { p { page-break-after : always } } <div class = "row"> <div> data1 </div> <p> break page here </p> <div> data2 </div> <div> ...

Blocking users on a PHP social networking platform

I'm in the process of developing a social networking platform and I am currently working on adding a feature that allows users to block other users. However, I am facing challenges when it comes to implementing this feature. In my database, there is ...

Is there a way for my element to fill the entire screen and prevent any scrolling from occurring?

I am looking to ensure that my children's div occupies the remaining space on the screen and prevent scrolling. Since I am utilizing PanZoom, I need the children's div to always fill 100% of the screen. <div class="parent"> &l ...

Assign individual buttons to specific CSS files to update the background image on my webpage

I'm experimenting with changing the background of my webpage using Angular framework. I want to switch between different CSS files by clicking on buttons within the same page. CSS1.css body { background-image: url("./Images/mg.jpg"); } CSS2.cs ...

How to set the default value for an angularJS select dropdown

Can someone assist me with setting a default value for a select dropdown using AngularJS? I have explored similar threads on StackOverflow, but none of the suggested solutions have resolved my issue. Therefore, I am reaching out to seek help here. Essenti ...

Receiving inaccurate video duration when the input bar is modified

Initially, I am uncertain whether the issue stems from Javascript or CSS. The code in question involves displaying the corresponding video time when a user hovers over an input bar. The calculation utilized is as follows: ((user mouseX position / input wi ...

Input form sending information to an incorrect destination URL

I'm struggling to get my form to pass a parameter to a link in the desired format: index.php?action=2&parameter=value Currently, it is only passing the parameter like this: index.php?parameter=value Here's the code I have been using : &l ...