How to make an html table deliberately exceed the width of its container?

ericgrosse

Demo

I'm trying to make a table that contains a horizontal scrollbar where the width of any individual row can be set to whatever I want. I've tried two different approaches to achieve this and they each give me problems:

If I assign a width to my table that is larger than its containing div and apply overflow-x: scroll, the table exceeds the width of its container. However, I have no control over the width of my cells. Setting td{width:'x'px;} doesn't do anything.

If instead I apply table-layout:fixed to the table, I can now adjust the width of individual rows but cannot exceed the width of the table container.

How do I get the best of both worlds? I need the table to exceed the width of the container in order to get the scrollbar, while also being able to set the width of different rows to any value.

light

HTML table and table cells work this way by design - cells will always be confined to within the width of the table. If you want to size them like you do to normal inline-block elements, you can either:

  1. Use <div class="table"> and <div class="cell"> to markup and style tables.

OR

  1. Change the display mode in CSS. {display: block} for tables, {display: inline-block} for cells. You'd probably also need to fiddle with the display modes of other elements like <tr>, <th>, <thead>, <tbody>...

A little note: just in case you are using tables as a means to layout your page content, please stop and strongly reconsider changing your approach. Tables are a nasty crutch for layout, and should really ONLY be used to display actual tabular data.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to make html table made by list responsive?

분류에서Dev

CSS: how to make a DIV with display: table-celll extend 100% in width

분류에서Dev

How to animate an image as it grows from the width of a container to the full viewport width?

분류에서Dev

How to get real width td table

분류에서Dev

How to stop table from adjusting width

분류에서Dev

How to set state of container component from its child in reactjs and reflux?

분류에서Dev

Set min-width in HTML table's <td>

분류에서Dev

table width not set in iTextSharp when converting html to PDF

분류에서Dev

How did this website hide its html

분류에서Dev

How can I make DataGrid columns stretch as the control changes width?

분류에서Dev

How can I make two iframes fit the width of the page?

분류에서Dev

How to make two divs of a total of 100% width fit in the screen

분류에서Dev

Stretch nested div width to width of container?

분류에서Dev

Centering unknown width object in an unknown width container

분류에서Dev

Random .HTML, how to make it stop

분류에서Dev

How to exceed 64 channels (bits) in this publishing system

분류에서Dev

How can I make the ul contain li in its content box?

분류에서Dev

How to make Teracopy close its window after transferring a file?

분류에서Dev

How to make this angular shaped border (as its shown in the image)?

분류에서Dev

How to set table width percentage using office js

분류에서Dev

How can i achieve truncated text in a responsive width table column?

분류에서Dev

C++: How to make a container indexed by std::function?

분류에서Dev

How to make the simplest <div>-like transparent container/layer in AndEngine?

분류에서Dev

CSS “display: table-cell” for columns - Make the width of first column the same as the widest word

분류에서Dev

How to extract text in html table

분류에서Dev

How to make function NOT highlight last row in table?

분류에서Dev

How do I make a table of indexes

분류에서Dev

How to print an HTMLElement's properties to console instead if its HTML code?

분류에서Dev

How to make an HTML link displayed as an icon accessible?

Related 관련 기사

  1. 1

    How to make html table made by list responsive?

  2. 2

    CSS: how to make a DIV with display: table-celll extend 100% in width

  3. 3

    How to animate an image as it grows from the width of a container to the full viewport width?

  4. 4

    How to get real width td table

  5. 5

    How to stop table from adjusting width

  6. 6

    How to set state of container component from its child in reactjs and reflux?

  7. 7

    Set min-width in HTML table's <td>

  8. 8

    table width not set in iTextSharp when converting html to PDF

  9. 9

    How did this website hide its html

  10. 10

    How can I make DataGrid columns stretch as the control changes width?

  11. 11

    How can I make two iframes fit the width of the page?

  12. 12

    How to make two divs of a total of 100% width fit in the screen

  13. 13

    Stretch nested div width to width of container?

  14. 14

    Centering unknown width object in an unknown width container

  15. 15

    Random .HTML, how to make it stop

  16. 16

    How to exceed 64 channels (bits) in this publishing system

  17. 17

    How can I make the ul contain li in its content box?

  18. 18

    How to make Teracopy close its window after transferring a file?

  19. 19

    How to make this angular shaped border (as its shown in the image)?

  20. 20

    How to set table width percentage using office js

  21. 21

    How can i achieve truncated text in a responsive width table column?

  22. 22

    C++: How to make a container indexed by std::function?

  23. 23

    How to make the simplest <div>-like transparent container/layer in AndEngine?

  24. 24

    CSS “display: table-cell” for columns - Make the width of first column the same as the widest word

  25. 25

    How to extract text in html table

  26. 26

    How to make function NOT highlight last row in table?

  27. 27

    How do I make a table of indexes

  28. 28

    How to print an HTMLElement's properties to console instead if its HTML code?

  29. 29

    How to make an HTML link displayed as an icon accessible?

뜨겁다태그

보관