Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6620019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:02:45+00:00 2026-05-25T21:02:45+00:00

Take the following CSS+HTML: <style> div.stuff { overflow: hidden; width: 100%; white-space: nowrap; }

  • 0

Take the following CSS+HTML:

<style>
    div.stuff {
        overflow: hidden;
        width: 100%;
        white-space: nowrap;
    }
    table { width: 100%; }
    td { border: 1px dotted black; }
</style>

<table>
    <tr><td>
        <div class='stuff'>Long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text</div>
    </td></tr>
</table>

This causes the table to grow to accommodate the entire long text. (Make your browser window smaller to see if you have a humongous screen resolution.)

I added width: 100% and overflow: hidden to indicate that the long text should simply be cut off, but it seems to ignore that. How do I constrain the table/the table cell/the div in such a way that the table’s width does not exceed the width of the document?

(Please don’t comment on the merits of using a table at all. I am indeed displaying tabular data, so the use of a table is semantically correct. Also please don’t question the user-friendliness of cutting off the text; there is actually an “expand” button that allows the user to view the full contents. Thanks!)

(Edit: I tried max-width too, to no avail.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:02:46+00:00Added an answer on May 25, 2026 at 9:02 pm

    To achieve this, you have to wrap the long text into two divs. The outer one gets position: relative and contains only the inner one. The inner one gets position: absolute, overflow: hidden, and width: 100% (this constrains it to the size of the table cell).

    The table-layout algorithm now considers those table cells empty (because absolutely-positioned elements are excluded from layout calculations). Therefore we have to tell it to grow that column regardless. Interestingly, setting width: 100% on the relevant <col> element works, in the sense that it doesn’t actually fill 100% of the width, but 100% minus the width of all the other columns (which are automatically-sized). It also needs a vertical-align: top as otherwise the (empty) outer div is aligned middle, so the absolutely-positioned element will be off by half a line.

    Here is a full example with a three-column, two-row table showing this at work:

    CSS:

    div.outer {
        position: relative;
    }
    div.inner {
        overflow: hidden;
        white-space: nowrap;
        position: absolute;
        width: 100%;
    }
    table {
        width: 100%;
        border-collapse: collapse;
    }
    td {
        border: 1px dotted black;
        vertical-align: top;
    }
    col.fill-the-rest { width: 100%; }
    

    HTML:

    <table>
        <col><col><col class="fill-the-rest">
        <tr>
            <td>foo</td>
            <td>fooofooooofooooo</td>
            <td>
                <div class='outer'>
                    <div class='inner'>
                        Long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>barbarbarbarbar</td>
            <td>bar</td>
            <td>
                <div class='outer'>
                    <div class='inner'>
                        Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text Some more long text
                    </div>
                </div>
            </td>
        </tr>
    </table>
    

    In this example, the first two columns will have the minimum possible size (i.e. spaces will make them wrap a lot unless you also add white-space: nowrap to them).

    jsFiddle: http://jsfiddle.net/jLX4q/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using simple html table with following css which will simply change background color
Take a look at the following HTML and CSS. .box { border-radius: 15px; border:
What's the simplest way to achieve the following with HTML/CSS: +---------+---------------------------------------------------+ | my |
i have following HTML structure: <div class=container> <div class=sidebar></div> <div class=content></div> <div class=subscript></div> </div>
I got a buttons row in the following html: HTML : <div class=buttons> <div><input
I would like to take requests for /somefolder/ style.css and handle them with /somefolder/
I have the following HTML: <div class=connections> <h2>Grads that share your interests</h2> <div id=connections_nav
I have the following html code : <div class=submit><input type=button name=getResult value=Get Comments class=sbutton
I need to do the following with my HTML with CSS: I need to
Take the following markup: <!DOCTYPE html> <html> <head> <title>My test for StackOverflow</title> </head> <body>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.