ben03 Posted December 11, 2018 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. Link to comment Share on other sites More sharing options...
dsonesuk Posted December 11, 2018 Share Posted December 11, 2018 Span is inline, inline element don't act upon width or height unless converted to block element. Link to comment Share on other sites More sharing options...
ben03 Posted December 12, 2018 Author Share Posted December 12, 2018 Thanks dsoneuk, I tried changing the span a div but am getting the same results? Link to comment Share on other sites More sharing options...
dsonesuk Posted December 12, 2018 Share Posted December 12, 2018 https://www.w3schools.com/code/tryit.asp?filename=FY56UVS31Y49 Link to comment Share on other sites More sharing options...
ben03 Posted December 12, 2018 Author 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 Link to comment Share on other sites More sharing options...
dsonesuk Posted December 12, 2018 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now