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

james

I have a table with 4 columns. The second column displays an email address and i'd like that column to take up the maximum amount of width within the table that it can. Then when the viewport size becomes smaller, the column width should be responsive and the email displayed should truncate if it becomes too large for the column.

All the solutions i've found so far either use table: {table-layout:fixed;} or set a max-width value on the td. Which are no good for me as they force the columns to specific widths.

This is what i'm trying to achieve regarding the column width layout, but the truncation fails. I read on an SO comment (showing the max-width solution) that setting width: 100% and min-width: 1px would have the desired affect, but it doesn't appear to work.

http://plnkr.co/edit/gIC5u6wq6oCYhF5pCJJp?p=preview

This is a max-width example where at least the text truncates, but the column widths are wrong.

http://plnkr.co/edit/e8sj2iqRUpBytMomddCS?p=preview

I've also tried wrapping the email text in a div, setting the width of the td to 100% and then setting the truncation on the inner div (also with width: inherit) but that didn't work either.

Domain

Add a class to other columns i.e Checkbox, Staff and Client columns and fix their width by giving appropriate widths.

Below is the HTML and CSS code:

HTML

<!DOCTYPE html>
<html>

  <head>
    <script data-require="jquery@*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script data-require="[email protected]" data-semver="3.1.1" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    <link data-require="[email protected]" data-semver="3.1.1" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
    <link href="style.css" rel="stylesheet" />
    <script src="script.js"></script>
  </head>

  <body>
    <div class="container">
      <div class="table-responsive">
        <table class="table table-bordered table-hover">
          <thead>
            <tr>
              <th></th>
              <th>Email</th>
              <th class="text-center">Staff</th>
              <th class="text-center">Client</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td class="text-center other-col">
                <input type="checkbox">
              </td>
              <td class="email-col">
                [email protected]
              </td>
              <td class="text-center other-col">
                yes
              </td>
              <td class="text-center other-col">
                no
              </td>
            </tr>
            <tr>
              <td class="text-center other-col">
                <input type="checkbox">
              </td>
              <td class="email-col">
                [email protected]
              </td>
              <td class="text-center other-col">
                yes
              </td>
              <td class="text-center other-col">
                no
              </td>
            </tr>
            <tr>
              <td class="text-center other-col">
                <input type="checkbox">
              </td>
              <td class="email-col">
                [email protected]
              </td>
              <td class="text-center other-col">
                yes
              </td>
              <td class="text-center other-col">
                no
              </td>
            </tr>
            <tr>
              <td class="text-center other-col">
                <input type="checkbox">
              </td>
              <td class="email-col">
                [email protected]
              </td>
              <td class="text-center other-col">
                yes
              </td>
              <td class="text-center other-col">
                no
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </body>

</html>

You can find that an additional class other-col is added in the above code.

CSS

/* Styles go here */
.email-col {
    /*width: 100%;
    min-width: 1px;*/
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.other-col {
  width:10%;
}

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

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

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

keep column width using responsive table bootstrap3

분류에서Dev

How can I achieve this tab style in android?

분류에서Dev

How can I give a table column name as "limit" in Postgres

분류에서Dev

How can I set auto-width/length on text input field?

분류에서Dev

How can I achieve Gigabit LAN speed without wires?

분류에서Dev

how can i achieve Null row after every sequence

분류에서Dev

Can I control word wrap or column width in htmlTable?

분류에서Dev

How can I move the images or the text within the column of a row such that it does not lose it's responsiveness?

분류에서Dev

Fixed right column table scales to responsive design

분류에서Dev

In my SQL query, how can I have a column with values queried from another table?

분류에서Dev

How can I query the same column in a kdb table multiple times in a single statement?

분류에서Dev

How do I insert column into table?

분류에서Dev

How can my sprite be responsive?

분류에서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

Zend 1 to Zend 2, was using decorators, how can i achieve the same behavior now?

분류에서Dev

How can I copy a text file into another?

분류에서Dev

How can I move text to the left with CSS?

분류에서Dev

How can I automate inputting text into a prompt?

분류에서Dev

Equal Column width on a table created by divs

분류에서Dev

How can I get data type of each column in a SQL Server table/view etc. using C# Entity Framework?

분류에서Dev

How can I get data type of each column in a SQL Server table/view etc. using C# Entity Framework?

분류에서Dev

How can i integrate php to html table

분류에서Dev

How to make html table made by list responsive?

분류에서Dev

Can achieve save space updating a column with html to null?

분류에서Dev

How to achieve this when I hover an flex item?

분류에서Dev

How do I use pandas to add a calculated column in a pivot table?

분류에서Dev

In protractor, how do I check if a table cell contains particular text?

분류에서Dev

How to set canvas width to width of canvas objects/text

Related 관련 기사

  1. 1

    keep column width using responsive table bootstrap3

  2. 2

    How can I achieve this tab style in android?

  3. 3

    How can I give a table column name as "limit" in Postgres

  4. 4

    How can I set auto-width/length on text input field?

  5. 5

    How can I achieve Gigabit LAN speed without wires?

  6. 6

    how can i achieve Null row after every sequence

  7. 7

    Can I control word wrap or column width in htmlTable?

  8. 8

    How can I move the images or the text within the column of a row such that it does not lose it's responsiveness?

  9. 9

    Fixed right column table scales to responsive design

  10. 10

    In my SQL query, how can I have a column with values queried from another table?

  11. 11

    How can I query the same column in a kdb table multiple times in a single statement?

  12. 12

    How do I insert column into table?

  13. 13

    How can my sprite be responsive?

  14. 14

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

  15. 15

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

  16. 16

    Zend 1 to Zend 2, was using decorators, how can i achieve the same behavior now?

  17. 17

    How can I copy a text file into another?

  18. 18

    How can I move text to the left with CSS?

  19. 19

    How can I automate inputting text into a prompt?

  20. 20

    Equal Column width on a table created by divs

  21. 21

    How can I get data type of each column in a SQL Server table/view etc. using C# Entity Framework?

  22. 22

    How can I get data type of each column in a SQL Server table/view etc. using C# Entity Framework?

  23. 23

    How can i integrate php to html table

  24. 24

    How to make html table made by list responsive?

  25. 25

    Can achieve save space updating a column with html to null?

  26. 26

    How to achieve this when I hover an flex item?

  27. 27

    How do I use pandas to add a calculated column in a pivot table?

  28. 28

    In protractor, how do I check if a table cell contains particular text?

  29. 29

    How to set canvas width to width of canvas objects/text

뜨겁다태그

보관