ben03 0 Posted December 11, 2018 Report Share Posted December 11, 2018 Hi there, I have been trying set a width of the last column in a table to 200px. <div class="table"> <div class="table-row"> <div class="table-cell">data</div> <div class="table-cell">data</div> <div class="table-cell"><span>data</span></div> </div> </div> .table{display: table;} .table-row{display: table-row;} .table-cell{display: table-cell;} .table-cell span{width: 200px;} Setting .table-cell:last-child to 200px causes strange behaviour with the height of the cells (this matters as a certain row is highlighted). Setting a width on the span solves the cell height issue, but the table still distributes the available space to each column evenly, so the last column is its natural width, plus 200px making it pretty wide. Is there a way to stop this last column filling out and remaining at 200px? Thanks. Quote Link to post Share on other sites
dsonesuk 929 Posted December 11, 2018 Report Share Posted December 11, 2018 Span is inline, inline element don't act upon width or height unless converted to block element. Quote Link to post Share on other sites
ben03 0 Posted December 12, 2018 Author Report Share Posted December 12, 2018 Thanks dsoneuk, I tried changing the span a div but am getting the same results? Quote Link to post Share on other sites
dsonesuk 929 Posted December 12, 2018 Report Share Posted December 12, 2018 https://www.w3schools.com/code/tryit.asp?filename=FY56UVS31Y49 Quote Link to post Share on other sites
ben03 0 Posted December 12, 2018 Author Report Share Posted December 12, 2018 Thanks for this, I found adding the width directly to the cell class caused cell height to play up sometimes though. Is there any way of telling a cell to collapse around an element with a fixed width inside it or does this sort of thing not exist? thanks Quote Link to post Share on other sites
dsonesuk 929 Posted December 12, 2018 Report Share Posted December 12, 2018 Depends on how the width of table and its cells are setup. If the cell width is wider than fixed width element it won't adjust to width of that fixed width element, in that case wouldn't it be better to adjust injected element to fill the width of cell instead. https://www.w3schools.com/code/tryit.asp?filename=FY5L17OFVQXV Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.