Designing a table with specific limitations on the width of each column

Having an issue with an HTML table that has 3 columns and specific restrictions:

  • Column 1: fixed width, no text wrapping (small text)
  • Column 2: allows text wrapping
  • Column 3: contains descriptive long text with wrapping enabled
  • A row should span the entire width of the page due to background coloring
  • Column 3 must have a minimum width of 70%
  • Column 2 should take up as much space as possible, but considering the restriction for Column 3, it should be, more or less, at maximum 30%

The provided code produces satisfactory results:

<!DOCTYPE html>
<html>
<body>

<table >
  <tr style="background-color:red;color:blue;">
    <td style="width:100px;">Jill</td>
    <td>Smith</td>
    <td style="min-width:70%;width:100%;">50</td>
  </tr>
  <tr >
    <td style="width:100px;">Eve</td>
    <td>Jackson</td>
    <td style="min-width:70%;width:100%;">94</td>
  </tr>
  <tr>
    <td style="width:100px;">John</td>
    <td >Doe</td>
    <td style="min-width:70%;width:100%;">80</td>
  </tr>
</table>

</body>
</html>

However, when replacing the text in the second column of the second row (i.e. Jackson) with a longer text like:

Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,

The layout becomes distorted, with the second column appearing small and no obvious way to increase its width.

Answer №1

When you add width:100% to the third column, it overrides the min-width:70% setting. To make the entire table full width, follow the updated code below:

<!DOCTYPE html>
<html>
<body>

<table style="width:100%">
  <tr style="background-color:red;color:blue;">
    <td style="width:100px;">Jill</td>
    <td>Smith</td>
    <td style="min-width:70%;">50</td>
  </tr>
  <tr>
    <td style="width:100px;">Eve</td>
    <td>Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,</td>
    <td style="min-width:70%;">94</td>
  </tr>
  <tr>
    <td style="width:100px;">John</td>
    <td>Doe</td>
    <td style="min-width:70%;">80</td>
  </tr>
</table>

</body>
</html>

Answer №2

While some may consider this approach a non-starter, tables are not always necessary for organizing information.

In my opinion, when creating a page like this, I would forego using a table and instead implement the Three Column Liquid Layout by Mathew Taylor as a starting point.... with the adjustment of swapping columns two and three.

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

Assistance requested with Javascript for an HTML dropdown menu

My question involves utilizing two HTML drop down menus. <select> <option value="">Please Select</option> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option ...

Bootstrap does not display unordered lists (<ul>) or ordered lists (<ol>)

I'm having trouble with my code that should display ordered and unordered lists. Even though I am using Bootstrap, I can't seem to get any list styling - no numbers or bullets are showing up. <ul> <li>test1</li> <li>test2 ...

:host-selector for Angular Material dialog

I am currently working with a dialog component provided by angular-material and I need to customize the appearance of the popup dialog. I am aware that there is some support for styling through the component generation: let dialogRef = dialog.open(MyDi ...

Using jQuery to enable scrolling and dynamically changing classes

I'm currently working on enhancing my website with a feature that changes the opacity of the first section to 0.4 when a user scrolls more than 400 pixels down the page. I attempted the following code without success: if($("html, body").offset().top ...

Tips for adjusting alignment in MaterializeWould you like to change the alignment

I have implemented the Materialize framework for my front-end design. Initially, everything looks good when the page loads, but upon returning to the index, there is an alignment issue. Clearing the cookies seems to fix it. Here is how it currently looks: ...

Remove the boundaries from the grid and only retain the box

I am not skilled in css, but I simply want to eliminate the interior edges of the box and retain only the outer edges. .grid-container { display: grid; grid-template-columns: auto auto auto; background-color: #2196F3; padding: 10px; } .grid-ite ...

Title slide on quarto featuring a captivating full coverage background image with a sleek row of icons at the bottom

I am currently working on creating a title slide for a reveal.js presentation in Rstudio using quarto. My goal is to have a background image covering the entire slide and include one or more small icons at the bottom (specifically on this slide only). I ha ...

Create a draggable and droppable file upload container that functions similarly to an input with the type "file"

My goal is to create a native HTML5 multiple file upload feature using drag and drop functionality. Despite following tutorials like and http://www.html5rocks.com/en/tutorials/file/dndfiles/, I have not yet found the exact solution I am looking for. Ess ...

Clicking on the spinner does not activate it

I've implemented a basic spinner on my website, and it works fine when using the keyboard. However, I'm experiencing issues with mouse clicks. I can't seem to figure out what is causing this problem. Below is the code snippet related to the ...

The back button fails to refresh the page on a website utilizing Ajax technology

Recently, I implemented AJAX on a client's website to introduce some smooth animations for page transitions. When navigating from the homepage of firedogcreative.com to the edit page, and then to one of the work pages, we see a history like this: fir ...

unwelcome tab spacing in CSS

I am facing an issue with unwanted spacing in my lists. I have a code that generates three-column lists, each containing about eight rows. However, the first list item of the last row is causing an unwanted space. It seems to shift entirely to the next col ...

Exploring jQuery: Choosing all li elements starting from a specific index to the end

Is there a way to select the last item, li:eq('+(lastItemIndex)+')', and all subsequent items until the end? Check out this JSFiddle demo for an example of changing elements in li from 3 onwards. ...

What are some techniques for applying CSS styling directly to a custom element?

Check out this amazing resource from HTML5 Rocks about the process of creating custom elements and styling them. To create a custom element, you can use the following code: var XFoo = document.registerElement('x-foo', { prototype: Object.crea ...

What is the rationale behind browsers on OSX not supporting the styling of HTML option elements?

As an OSX user, I primarily use Chrome and recently discovered that styling the HTML option element is not applied in any browser (Chrome, Firefox, Safari) on OSX. // HTML <select> <option class="option">Value 1</option> < ...

Chrome stack router outlet and the utilization of the Angular back button

I'm experiencing an issue with the back button on Chrome while using Angular 14. When I return to a previous page (URL), instead of deleting the current page components, it keeps adding more and more as I continue to press the back button (the deeper ...

What steps can be taken to reduce the size of the cards in ant.design?

Currently, I am using the ant.design Card component to present messages in a chat webapp built with react/redux. However, each card is displaying too much space around the text. Is there a way to adjust the card so that it wraps the text more closely? htt ...

What steps can I take to prevent Internet Explorer from caching my webpage?

After implementing Spring MVC for Angular JS on the front end, I encountered an issue where logging in with different user credentials resulted in incorrect details being displayed. This problem only occurred in Internet Explorer, requiring me to manually ...

Tips for adjusting the time interval on an automatic slideshow when manual controls are in play

I'm having trouble with my slideshow. I want it to run automatically and also have manual controls, but there are some issues. When I try to manually control the slides, it takes me to the wrong slide and messes up the timing for the next few slides. ...

What is the best way to create divs that can close and hide themselves when clicked from inside the div itself?

I have a situation in my code where clicking a link reveals a div, and then the same link must be clicked again to hide it. However, I want to modify this so that any link within the div can also hide it when clicked. I currently have eight divs set up lik ...

The v-menu closes before the v-list-item onclick event is detected

I have set up the following menu using vue and vuetify: <div id="app"> <v-app id="inspire"> <div class="text-center"> <v-menu> <template v-slot:activator="{ on }"> ...