开发者

Table CSS not working when using position

开发者 https://www.devze.com 2023-04-07 02:17 出处:网络
I am experimenting with a fixed header table 开发者_如何学JAVA(I have seen many plugins online but I want to do it myself using PURELY CSS) at http://dev.driz.co.uk/table.html

I am experimenting with a fixed header table 开发者_如何学JAVA(I have seen many plugins online but I want to do it myself using PURELY CSS) at http://dev.driz.co.uk/table.html

However I have two issues:

  1. The headers doesn't stretch the width of the table anymore and is no longer in sync with the table rows below. How do I fix this?

  2. I have put a border around the table and also around the table cells and so have now ended up with double borders in some places. How can I get around this? As I need the table to have the border as the cells will not always be on screen and cannot be relied on to provide the box around the table.

If someone can help, it'd be much appreciated.


Through experimenting I've found that position:absolute on either tbody or thead is causing the issue where your table head items aren't lining up to the table data. Absolutely positioning an element breaks it out of the rendering flow of the page. So adding position:absolute to thead causes the header items to collapse to the content in them and adding it to tbody breaks the table data cells from normal flow which means thead cannot relate its cell widths to tbody's.

This is just what I've found but if I'm wrong I'm open to correction.


Using table-layout: fixed; solves the issues!

0

精彩评论

暂无评论...
验证码 换一张
取 消