10

I trying to create a table cell <td> with an overflow but it doesn't work...

There's my CSS code:

td.blog_content
{
    max-height: 50px;
    overflow: auto;
    width: 360px;
    text-align: left;
    padding: 2px;
}

And my HTML:

<td class="blog_content"><?php echo $blog['content']; ?></td>

It would create a simple box with a scrollbar if the text is too long...

10
  • 1
    And of course we wouldn't use a <table> for styling so .blog_content is obviously tabular data ;) Commented Feb 5, 2012 at 19:01
  • 1
    What a title... "CSS styling doesn't work". Good, we can just fire all our designers then, they've been doing it wrong all these years. Commented Feb 5, 2012 at 19:02
  • @Ktash It's only the part where I have a bug... Commented Feb 5, 2012 at 19:04
  • 2
    @FrederickMarcoux A bug? That's what we're here for ;) Modern CSS can handle most any situation a table can. Commented Feb 5, 2012 at 19:06
  • 1
    @FrederickMarcoux Like I said, modern CSS can handle most anything. This means we can make IE7+ (which is CSS2 +some) support most anything a table can do. If you're talking CSS3, than there is nothing a table can do that CSS can't. If you'd like to get it fixed, I'd recommend posting it as a question as many here in the community (myself included at times) are good at solving those issues. Commented Feb 5, 2012 at 19:14

5 Answers 5

8

Try wrapping it in a <div>. I'm pretty sure the overflow attribute is not defined for a <td> element, at least in HTML4 it's not.

<td class="blog_content">
    <div><?php echo $blog['content']; ?></div>
</td>

.blog_content div {
    height: 50px;
    max-height: 50px;
    overflow: auto;
}
Sign up to request clarification or add additional context in comments.

1 Comment

You'll need to wrap it in a <div> in HTML5 too
2

Set table-layout: fixed; on the table containing your cells. Alternatively, wrap the contents of each cell in a div and apply the styles to that.

1 Comment

Are you sure the table-layout property affects this? I can't seem to get it to work.
2

It seems like you have to wrap the contents into a div:

<td class="blog_content"><div><?php echo $blog['content']; ?></div></td>

td.blog_content div
{
    max-height: 50px;
    overflow: auto;
    width: 360px;
    text-align: left;
    padding: 2px;
}

Demo: http://dabblet.com/gist/1747301

Comments

1

I'm not sure you can force scrollbar by overflow: auto in a table-cell, but you sure can with a div-tag. Have you considered using a div?

Comments

1

You can put :

<td class="blog_content">
  <div style="overflow:auto;width:200px;">
      <?php echo $blog['content']; ?>
  </div>
</td>

Adding a DIV element will with fixed height or width and overflow property to auto will make it scroll.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.