Setting the width of a group of <td> elements using HTML and CSS

Consider the following table structure:

    <table>
      <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
    </table>

Can we ensure that the first two data cells and the last two data cells always take up 50% of the total width collectively? If one cell expands, the other will shrink to maintain their total width at 50% of the entire table. For example:

|1 |2 |3 |4 |

can transform into

|1 |2 |3 |4 |

where the position of 1 and 3 remains fixed, as does the position of 2 and 4.

NOTE: It would be preferred if this can be achieved without nesting within a second table to contain the pair of <td> elements.

Answer №1

Here is a workaround you can consider using:

.fifty {
  width: 50%
}
<table>
  <tr>
    <td class="fifty" colspan="2">foo</td>
    <td class="fifty" colspan="2">bar</td>
  </tr>
  <tr>
    <td>foo bar</td>
    <td>foo foo bar</td>
    <td>foo foo</td>
    <td>foo bar</td>
  </tr>
</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

Utilize a pair of drop-down menus to concurrently filter a data table

I am interested in implementing two select option filters on a datatable at the same time. Currently, they function well when individually selected, but do not work together for filtering by two variables simultaneously. Currently, selecting a second filt ...

Using Vanilla JavaScript to Disable a Specific Key Combination on a Web Page

On a completely random English-Wikipedia editing page, there exists a way to add content (for example, "test") and save it using the existing key combination of Alt+Shift+S. My goal is to specifically prevent this action without removing the save button b ...

Automatically retrieve the generated PDF file upon completion (Node.js and Express)

I've been utilizing the node module html-pdf to seamlessly convert my HTML into PDF format. The conversion process goes smoothly, but I'm encountering difficulties when it comes to downloading the file once it's been generated. Below is the ...

Tips for creating a layout with two responsive columns side by side: one with text and the other with an image, using Bootstrap 4

How can I create two responsive columns in Bootstrap 4, one with text and the other with an image, similar to the layout shown in the image below? <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" int ...

The inline-block property can become unstable when dealing with a large number

When I create a parent container div with three child divs and set the display property to inline-block, everything looks great on jsfiddle CSS #container { border: 1px solid blue; padding: 2px; display: inline-block; } .child { width: ...

Having issues with find_previous_sibling method in BeautifulSoup not yielding the expected results

I've been working on extracting data from a website (). While I have successfully retrieved some values like name, model, price, and fuel type, I am encountering difficulties with the "year" and "kilometers" fields. The code consistently returns "N/A" ...

Experience an enhanced replay of canvas drawings with advanced line smoothing technology

Enter your name on the canvas below, and the code will save the drawing coordinates in an array. However, I am having trouble replaying the drawing using these coordinates. It seems to be drawing too quickly! What would be your approach to resolve this is ...

What is the best way to prevent clicking and scrolling on a webpage?

I have added a "more" button to the bottom left of my website to reveal a menu. Upon clicking the button, the plus sign changes to an x. I would like the page to disable click and scroll actions when the plus sign is clicked. <div class="dropup"> ...

"Bootstrap is functioning properly on my local environment, but it seems to

Utilizing the MVC framework and bootstrap has been successful for optimizing my website locally. However, when I upload it to the server, none of the CSS is being rendered. Additionally, the front page, meant to be a carousel slider, appears as a vertical ...

Choosing pseudo-elements with CSS styling rules

I have been utilizing the Brave browser to block online ads. However, certain websites have found a way to insert ads into their HTML on the server-side, bypassing my ad-blocking efforts in Brave. Currently, Brave only offers the ability to block elements ...

Changing the background color of UILabel in iOS with a rounded rectangle design

I am looking to create a design similar to this concept. https://i.sstatic.net/7ZQi3.png One approach is to achieve this by inserting an image (for "PDF"). NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage image ...

What could be causing the background color opacity of the HTML hr tag to decrease?

I am trying to modify the height and background color of the <hr> HTML tag. However, even though the height and color are changing, it appears that the background color opacity is decreasing slightly. What could be causing this issue? Here is my cod ...

Is it possible to achieve a high quality image with a file size less than 2.0MB?

Could someone knowledgeable in website design and development please explain the technique used by Google, Microsoft, and other websites to feature high-resolution photos as backgrounds on their webpages while maintaining a small file size? Here are some ...

Issues with Body Background Images

I am encountering multiple issues with the background image on my website. The initial problem arises when the screen is smaller than the content, and users scroll horizontally to view cut-off content resulting in the background image being cutoff to the w ...

Fix the style of the CSS for the Bootstrap button

I am currently testing two social media buttons, one using an Anchor Tag and the other using a Button Tag for experimental purposes. The problem I am facing is that when I click on the button, its color and border change to the default bootstrap .btn styl ...

I'm new to Angular and I'm wondering how to close the panel by clicking on the 'x' button and also by clicking on the screen. Can anyone help me with this

Below is the HTML code I use for my button: <button class="btn btn-outlined " ng-click="vm.showCommentBox1()">Notify All</button> <div class="comment-box custom saveAll" ng-if=""><div class="panel panel-default"> ...

Require assistance with arranging font-awesome icons in a stacked formation

After upgrading to the latest version of font-awesome, I encountered some stacking issues with my icons. In the previous version, everything was working perfectly. <li><span class="icon-stack stacked"><i class="icon-circle icon-stack-base" ...

Forget the function once it has been clicked

I'm looking for a solution to my resizing function issue. When I press a button, the function opens two columns outside of the window, but I want to reset this function when I click on another div. Is there a way to remove or clear the function from m ...

PHP code to display or conceal tables

I am facing a challenge in my PHP code where I need to hide a table based on a specific condition. Despite trying to use CSS for this purpose, it seems that CSS does not recognize the if condition and always overrides it. I am looking for a solution that ...

I aim to display my popup only once per day

Is there a way to display this popup only once per day? <span id='close' onclick='this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); return false;'>x</span> <iframe width="360" height="240" sr ...