Expanding the rowspan within a table column has the effect of reducing its overall width

I have created a table with two rows, where the first row has three columns and the second row has two columns. The middle column in the first row has been set to rowspan="2". However, the issue is that it appears smaller than its intended width.

.kolona {
  background: white;
  height: auto !important;
}
td { width: 100%; }
#langas td { border: 1px solid black; }
#langas { border: 1px solid black; }
#langas td td { /* empty */ }
.lightblue { background-color: lightblue; }
table { border-collapse: collapse; }
td { width: auto; }
table table {
  height: 100%;
  border: 0;
  width: 100%;
}
#langas tbody { border-spacing: 2px; }
tbody {
  width: 100%;
  display: inline-table;
  border-collapse: initial;
}
.bb { height: 30px; }
.img-bg {
  top: 0;
  left: 0;
  position: absolute;
  width: 100%;
  height: 100%;
  /* background: no-repeat url( data url ); */
  z-index: 555;
}
.window-col {
  position: relative;
  -moz-box-sizing: border-box; 
  -webkit-box-sizing: border-box; 
  box-sizing: border-box; 
}
tr { /* empty */ }
.kampuciai .kampuciai-bf:before {
  background: #000;
  content: "";
  width: 2px;
  height: 11px;
  position: absolute;
  bottom: -2px;
  left: 3px;
  margin-top: 1px;
  transform: rotateZ(45deg);
  width: 1px;
}
.kampuciai .kampuciai-bf:after {
  background: #000;
  content: "";
  width: 2px;
  height: 11px;
  position: absolute;
  bottom: -2px;
  right: 3px;
  margin-top: 1px;
  transform: rotateZ(-45deg);
  width: 1px;
}
.kampuciai {
  padding: 5px;
}
.kampuciai:before {
  background: #000;
  content: "";
  width: 2px;
  height: 11px;
  position: absolute;
  top: -3px;
  left: 3px;
  margin-top: 1px;
  transform: rotateZ(-45deg);
  width: 1px;
}
.kampuciai:after {
  background: #000;
  content: "";
  width: 2px;
  height: 11px;
  position: absolute;
  top: -3px;
  right: 3px;
  margin-top: 1px;
  transform: rotateZ(45deg);
  width: 1px;
}
#langas tbody tbody td {
  height: 100%;
  position: relative;
}
.top-units {
  border-left: 1px solid #000;
  border-right: 1px solid #000;
}
* { /* empty */ }
.frame-units .units {
  background-color: #ededed;
  max-width: 60px;
  margin: 0 auto;
  font-family: Arial,Helvetica,sans-serif;
  font-size: 11px;
  display: block;
  color: #000;
}
.top-units .units { text-align: center; }
.top-units td {
  border-left: 1px solid #000;
  border-top: 1px solid black;
  height: 30px;
}
.top-units td:first-child { border: none; }
.frame-units .unit-block {
  position: relative;
  width: 100%;
}
.main-unit-block-width .units, .main-unit-block-height .units {
  width: 70px;
  max-width: 70px;
  margin-bottom: 10px;
}
.top-units .units { text-align: center; }
.frame-units .units {
  background-color: #ededed;
  max-width: 60px;
  margin: 0 auto;
  font-family: Arial,Helvetica,sans-serif;
  font-size: 11px;
  display: block;
  color: #000;
}
#t_width, #r_height { width: 39px; }
.frame-units .u-bubble {
  background: #fff;
  font-size: 15px;
  width: 30px;
  color: #000;
  border: none;
  border-radius: 5px;
  padding: 2px 2px;
  text-align: right;
}
.frame-units .units .unit { margin-left: 4px; }
.upper-measures, .upper-measures tbody, .upper-measures tbody tbody {
  border-collapse: collapse!important;
}
#langas tbody tbody { height: 100%; }
  .right-units {
  border-top: 1px solid #000;
  border-bottom: 1px solid #000;
}
/* .right-units td { background: url( absolute url ) repeat-y 15px top; } */
.right-units table tr:last-child td { border: none; }
.right-units table td { border-bottom: 1px solid black; }
.right-units .unit-block { /* empty */ }
.right-units .units {
  position: relative;
  top: 15px;
  margin-left: 10px;
}
.varstymas {
  width: 100%;
  height: 100%;
}
.bb td { border:1px solid black; }
.bb { height: 100%; }
.paskutinis-borderis { padding: 5px; }
.duru-img { width: 100%; }
.kolonos-plotis:disabled { background: #ededed; }
.kolonos-aukstis:disabled { background: #ededed; }
.inputErr { border: 1px solid red; }
.st0 { fill:#AFB2B4; }
<table id="langas" style="height: 302px; width: 302px;">
  <tbody style="height: 300px; width: 300px;">
    <tr id="window-row-0" class="window-row">
      <td rowspan="1" colspan="1" class="window-col" style="padding: 0px;height:150px;line-height:0px;width:100px;" id="window-col-0-0">
        <div id="img-bg-0" class="img-bg"></div>
      </td>
      <td rowspan="2" colspan="1" class="window-col" style="padding: 0px;height:150px;line-height:0px;width: 100px;" id="window-col-0-1">
        <div id="img-bg-1" class="img-bg"></div>
      </td>
      <td rowspan="1" colspan="1" class="window-col" style="padding: 0px;height:150px;line-height:0px;width:100px;" id="window-col-0-2">
        <div id="img-bg-2" class="img-bg"></div>
      </td>
    </tr>
    <tr id="window-row-1" class="window-row">
      <td rowspan="1" colspan="1" class="window-col" style="padding: 0px;height:150px;line-height:0px;width:150px;" id="window-col-1-0">
        <div id="img-bg-0" class="img-bg"></div>
      </td>
      <td rowspan="1" colspan="1" class="window-col" style="padding: 0px;height:150px;line-height:0px;width:150px;" id="window-col-1-1">
        <div id="img-bg-1" class="img-bg"></div>
      </td>
    </tr>
  </tbody>
</table>

I have noticed that increasing the middle column width to 150px resolves the visual discrepancy, but this workaround is not sustainable as the values will be dynamically inputted. What could be causing this issue, and what would be the appropriate approach to resolve it?

Answer №1

To achieve a specific layout for tables, we can utilize the table-layout property in CSS.

table{ table-layout:fixed; }

With this property, the widths of the table and columns are determined by either the specified widths of the table and col elements or by the width of the first row of cells. The widths of cells in subsequent rows do not impact column widths. When no widths are defined for the first row, the column widths are distributed equally across the table, regardless of cell content.

As a result, there is no need to manually set individual widths for each column as they will be automatically calculated based on the overall table width and the columns used within rows.

For further information, visit https://www.w3schools.com/cssref/pr_tab_table-layout.asp

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

Reposition div when clicked

I have encountered a challenge where I am unable to perform a small task. My goal is to have the position of "div1" change upon clicking on "div2", taking into account that "div2" is nested inside "div1". Additionally, when clicking on "div2" again, "div1" ...

Retrieve data from the database and automatically populate all text fields when the dropdown value is modified

I need assistance with populating all textbox values based on the dropdown selection. The dropdown values are fetched using an SQL query. Here is the HTML Code: <select name="name" ID="name" class="form-control"> <opt ...

Maximizing the width of navbar elements with Bootstrap 3

I am currently working on building a webpage with bootstrap3, but I have encountered an issue with the navigation bar. I would like the navigation links ("Web Design", "Development", "Photography", "Blog") to be evenly spaced out within the horizontal na ...

What is the best way to ensure my images are responsive to the varying device sizes when displayed on this website?

In my endeavor to design a 2-column layout using Bootstrap, I aim for each row to consist of two columns: One column will contain text, while the other will display images that complement the textual content. Below is the Bootstrap code snippet for the n ...

How can I prevent an endless loop in jQuery?

Look at the code snippet below: function myFunction(z){ if(z == 1){ $(".cloud").each(function(index, element) { if(!$(this).attr('id')){ $(this).css("left", -20+'%'); $(this).next('a').css ...

both modules loading at the same time in AngularJS

var moduleA=angular.module("MyModuleX",[]); moduleA.controller("MyControllerX",function($scope){ $scope.name = "John X"; }); var moduleB=angular.module("MyModuleY",[]); moduleB.controller("MyControllerY", function($scope) { $scope.name = "Sarah Y" ...

What is the process for creating a default button in Ionic framework?

Recently, I developed an app that includes a survey page. Each question in the survey has two buttons for the user to select: Yes or No. However, as a newcomer to using Ionic, I encountered an issue after building the code and checking the output. One of ...

Customize the appearance of the search box in Serverside Datatables

Is there a way to adjust the search and show inputs for datatables so that I can customize their width and make them fit my dynamic column sizing? The issue I ran into is that these inputs are enclosed within <label> tags in the source JavaScript, an ...

Using an external JavaScript script may encounter difficulties when loading pages with jQuery

Trying to utilize jQuery for loading html posts into the main html page and enabling external scripts to function on them. Utilizing a script (load.js) to load posts into the index.html page: $(document).ready(function () { $('#header').loa ...

Is there an advantage to pre-rendering a circle on an HTML5 canvas for improved performance?

Is it more efficient to pre-render graphics for a basic shape like a circle on an off-screen canvas? Would there be noticeable improvements in rendering performance when dealing with 100 circles at game-like framerates? What about 50 circles or just 25? ...

Overflowing Collection of Hidden CSS Assets

Here is a unique question. I'm currently implementing some CSS lasers for a futuristic website design: https://codepen.io/jefferymills/pen/xpmDK The code below showcases how to incorporate the lasers using HTML: <div class="laser-beam"></di ...

Is there a more efficient way to optimize my coding for this Cellular Automata project?

As a beginner in programming, I wanted to delve into the world of cellular automata and decided to create my own using JavaScript. The project involves a simple binary (black and white) 2D CA where each cell updates its color based on the colors of its 8 ...

Struggling to fetch option value from a dynamic add/remove list using a combination of PHP, jQuery, and HTML5

Having trouble accessing and displaying values from a select list. Constructed an add/remove list functionality using JQuery but unable to showcase the values using foreach and for loops. Specifically trying to obtain $existing_mID[$j] values from the &apo ...

How to align text vertically in a cell alongside a button in another cell using Bootstrap

In my table, I have 3 columns of text and a fourth column with a button. The alignment of the text in the cells does not match the button text vertically due to the button having a vertical-align value of 'middle'. To align them properly, I curre ...

Issue with CSS: 200vw not scaling correctly for mobile devices

I'm attempting to create a horizontal slide effect between two div elements, so here is the HTML code: <div id="container"> <div class="viewport-1"> <div class="inner-div"> <h1>Viewport background 1</h1></ ...

Styled Components do not have the ability to define :hover states

export const WatchVideoButtonWrapper = styled.div` position: absolute; bottom: 80px; right: 33px; background-color: ${(props) => props.bgColor}; color: ${(props) => props.color}; border-radius: 100px; transition: all 0.1s; ...

I am having trouble getting my console.log function to work properly on my HTML page

As a beginner in JavaScript, I am facing an issue with my console.log not working at all. When I type a console.log message, nothing shows up on my HTML page. I have tried to debug it, but being a newbie, I lack the necessary knowledge. All I can do is see ...

Flexbox - Consistent height image columns

I'm working on a basic flexbox layout that looks something like this: html,body { margin:0; padding:0; } body { height:100%; width:100%; } .panel-grid { -webkit-align-items: flex-start; ...

Struggling to effectively customize a bootstrap theme

After incorporating a custom .css file from an internet theme that overrides some bootstrap properties, I noticed that it works in certain scenarios. However, when attempting to modify the primary color in the :root{} section of the styles.css file, the ch ...

Creating a centered horizontal line in a table cell using CSS

element, imagine placing a line in the middle of a table cell (td) like this: To achieve this effect, you can insert a line within the td as shown in the image below: This allows you to write text while keeping the line visible in the background, almost ...