Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the maximum width of a table

I'm trying to set the maximum width of a table, but it doesn't seem to be working. If a word inside the table is too long, it automatically expands the width of the table. How do I stop that from happening, and instead have the word that's too long go to the next line?

<style>table {
  max-width: 300px;
}

table,
td {
  border: 1px solid red;
}

div {
  border: 1px solid blue;
  word-wrap: break-word;
}

</style>
<table>

  <tr>
    <td>
      <div> hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
      </div>
    </td>
  </tr>

</table>
like image 340
frosty Avatar asked Oct 15 '16 19:10

frosty


People also ask

How do you set the maximum width of a table?

If you want to make your max-width to work, you need to set the CSS property table-layout: fixed; on the table and use width , not max-width . Save this answer. Show activity on this post. Add the following rule your css section.

What should I set my max width to?

If the majority of your traffic, or potential traffic, won't ever see your website over 1366 pixels, then a max-width of around 1400 pixels is a safe bet. Pros: Having a max-width makes it generally easier to manage the layout of your content, and said content can quickly be absorbed by your audience.

How do you define max width?

Definition and UsageThe max-width property defines the maximum width of an element. If the content is larger than the maximum width, it will automatically change the height of the element. If the content is smaller than the maximum width, the max-width property has no effect.

Why set a max width?

The max-width CSS property sets the maximum width of an element. It prevents the used value of the width property from becoming larger than the value specified by max-width .


1 Answers

If you want to make your max-width to work, you need to set the CSS property table-layout: fixed; on the table and use width, not max-width.

https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout

like image 130
th7nder Avatar answered Sep 28 '22 08:09

th7nder