Is there a non-table layout method to achieve equal width sharing with a fixed solution?

If I have n different elements to be placed in the same horizontal space, each taking up 100% of the screen width, for example:

<table style="width:100%;text-align:center;table-layout:fixed">
  <tr>
    <td><input/></td>
    <td><span>TEXT</span></td>
    <td><select><option>Something</option></select></td>
  </tr>
</table>

They all have equal width and adjust automatically when the screen width changes.

If one or more of the elements can be removed (display: none) or simply doesn't exist, it's important that the widths remain the same, like this:

<table style="width:100%;text-align:center;table-layout:fixed">
  <tr>
    <td><input style="display:none"/></td>
    <td><span>TEXT</span></td>
    <td></td>
  </tr>
</table>

As you can see, the span is still centered. This can be achieved with table-layout:fixed.

I'm curious if there's an alternative solution that doesn't involve using the table tag. Perhaps a solution using the div tag with display:grid or display:flex?

P.S. No fixed widths or calculations, just pure CSS

Answer №1

If you want to create a layout using HTML and CSS, consider using <div> with the property display: flex;.

Here's an example:

<div class="row">
  <div class="column">
    <input class="input" type="text">
  </div>
  <div class="column">
    <span class="span">TEXT</span>
  </div>
  <div class="column">
    <select class="select">
      <option>Something</option>
    </select> 
  </div>
</div>

To style this layout, add the following CSS:

.row {
  display: flex;
  flex-direction: row;
}

.column {
  display: flex;
  flex: 1;
}

.input {
  display: none;
}

By applying display: none; to the <input>, you can see that the column remains present but empty.

Answer №2

By applying the display:none property to the <input> within the <td> element, you are effectively hiding only the input field, while the <td> remains visible but empty. To completely eliminate the empty space, consider utilizing the

<td style="display:none"><input></td>
approach instead.

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

Angular material is experiencing an issue where content is being cut off or

I am currently working on a project using AngularJS for a web application. I have encountered an issue where some of the content in the md-content element is being clipped. For instance, the body tag has the style: overflow: hidden, and the child md-conte ...

How to customize JavaFx context menu appearance using CSS to achieve a full-width background color

I am trying to customize my context menu, but I'm having trouble with the white space between the menu item and the context menu border. Here is an example: view the rendered context menu with CSS styles What I want is for the color to fill the entir ...

Icon that can be clicked before

I'm struggling to figure out how to make the link icon in my code clickable so that users can click anywhere within the card to navigate to another page. I experimented with (" attr(href) ") but it resulted in adding the URL text next to the ...

When attempting to utilize res.sendfile, an error arises indicating that the specified path is incorrect

I am facing an issue with my Express.js server and frontend pages. I have three HTML and JS files, and I want to access my homepage at localhost:3000 and then navigate to /register to render the register.html page. However, I am having trouble specifying t ...

"Add a +1/Like/Share feature to enhance the user experience of your mobile web

In the process of developing a web-based mobile application with jQuery Mobile. Looking to incorporate buttons for "+1" and "Share" (for Google+) as well as "Like" and "Share" (for Facebook), but each button utilizes a popup window which goes against crea ...

Manage form submission seamlessly without redirecting. Capture information without needing to prevent the default action, then proceed with redirection. Avoid redirecting when using preventDefault, but be aware that data may not

Currently stuck in a tricky situation. I've implemented a custom form submission to prevent redirecting when an express route is triggered by form submission. However, the issue arises when I lose the data being sent without redirection. document.get ...

Running system commands using javascript/jquery

I have been running NodeJS files in the terminal using node filename.js, but now I am wondering if it is possible to execute this command directly from a JavaScript/jQuery script within an HTML page. If so, how can I achieve this? ...

Crafting an iframe that dynamically adjusts with Tailwind CSS

I'm having trouble ensuring that an iframe fits properly within a div while using tailwind CSS. I'm struggling to make the iframe responsive, no matter what class I try. Can anyone suggest a class that would help me achieve responsiveness for an ...

Is the button not aligned properly with the email input field?

<div class="subscribe__form--action--btn"> <form action="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32545b5e5b5746545C5B5356477F54585850"> </a>" meth ...

What types of events can be used to trigger the start of HTML5 audio playback in mobile Chrome?

When it comes to mobile browsers, Audio elements require user action before play can start. The click event usually satisfies this requirement, but touchstart doesn't seem to be an acceptable initiating event in Chrome on Android or iOS. (Refer below ...

Should the HTML inputs be positioned within the label or placed outside of it?

Check out this site for some on/off switches: <div class="onoffswitch"> <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked> <label class="onoffswitch-label" for="myonoffswitch"> < ...

Shifting an image within a canvas upon loading the webpage

Demo var stage = new Kinetic.Stage({ container: 'container', width: 578, height: 200 }); var layer = new Kinetic.Layer(); var imageObj = new Image(); imageObj.onload = function() { var yoda = new Kinetic.Image({ x: ...

There seems to be a hitch in the functioning of the JavaScript codes

I'm having trouble calculating the amount using jQuery. Could someone please review my code and let me know what's wrong? Here are my Javascript and jQuery codes: After making changes: $(document).ready(function() { $('.home_banner&ap ...

When an HTML table utilizes both rowspan and colspan attributes, it may encounter issues with being overlapped by the

I'm working on a straightforward table that showcases the properties of a data element. Each row will represent an element from the AJAX response in a list format. The table is designed with "rowspan" and "colspan" to expand specific cells. However, ...

Is it possible to activate a block display for an article based on the class value when a radio

Here is the HTML code snippet I'm working with: <div id="contentapp"> <input type="radio" name="menu" id="interest" checked> <input type="radio" name="menu" id="about"> <div id="tab"> <label for="intere ...

Is it possible to display a div when hovering over it and have it remain visible until

How can I make the div ".socialIconsShow" fade in when hovering over ".socialIcons", and then fade out when hovering over ".socialIconsShow"? Is there a way to keep the icons visible even after leaving ".socialIcons"? <div class="socialNetworks"> ...

What is the best method for eliminating HTML line breaks <br />?

I have gathered a collection of reviews from web scraping, but unfortunately they are filled with unwanted <br \> tags. Even after cleaning the data by removing stopwords, I still find several lingering instances of the "br" tag in the dataset. ...

Can anyone provide guidance on locating the parent of a pseudo element with Selenium WebDriver?

Is there a way to retrieve the parent web element of a pseudo element (if we can call it the parent) using JavaScript? I know that Selenium's methods for searching for web elements are not suitable for pseudo elements, but JavaScript does allow manipu ...

Ways to ensure the height of an element is consistent across various device modes

Testing out the angular-youtube-embed plugin with Chrome Dev tools' device mode, I wanted to see how the YouTube element would appear. Here's my code: <div class="fixed-header my-video"> <div style="padding:0px;"> <yo ...

How can I adjust the height of an iframe dynamically using AngularJS?

I wrote a function that resizes the height of an iframe element to always be 100% after it loads: app.directive('iframeAutoSize', [function() { return { restrict: 'A', link: function(scope, element, attrs) { ...