Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table-cell property ignores width

I have set a CSS property table-cell for a div. I have also specified the width for the div and set overflow hidden, but because of the table-cell property the div does not care about the width. If I place any large image, it goes out of the width. How can I use the table-cell and use the fixed width for the div?

.right{
    display: table-cell;
    overflow: hidden !important;
    vertical-align: top;
    width: 400px;
}
like image 408
user1251698 Avatar asked Oct 24 '12 10:10

user1251698


People also ask

How do you fix a cell width in a table?

Select your table. On the Layout tab, in the Cell Size group, click AutoFit. Click Fixed Column Width.

How do I fix the width of a table in HTML?

To set the table width in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property width.

How do you create cell width in a table?

This can be done by setting table-cell style to width: auto , and content empty. The columns are now equal-wide, but holding no content.

How do you adjust the width of a TD table?

To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively. Just keep in mind, the usage of style attribute overrides any style set globally.


1 Answers

Strange, this JSFiddle seems to work for me.

What browser are you having problems in?

Also, to force a maximum width for your table cells, use the max-width property. You can see it here, and the code is below.

HTML:

<div class='table'>
  <div class='tr'>
    <div class='right'>hey</div>
  </div>
</div>​

CSS:

.table {
    display: table;
}
.tr {
    display: table-row;
}
.right{
    display: table-cell;
    overflow: hidden !important;
    vertical-align: top;
    max-width: 400px;
    outline: 1px solid #888;
}​
like image 76
jamesplease Avatar answered Sep 28 '22 13:09

jamesplease