Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS to make table 100% of max-width

Tags:

Given the following for an email template:

<style>   @import url("http://fonts.googleapis.com/css?family=Open Sans"); </style>  <div style="width:100%; background:#F2F2F2">   <table style="padding: 25px; margin: 0 auto; font-family:'Open Sans', 'Helvetica', 'Arial';">     <tr align="center" style="margin: 0; padding: 0;">       <td>         <table style="border-style:solid; border-width:2px; border-color: #c3d2d9;" cellspacing="0">           <tr style="background-color: white;">             <td style="width: 700px; padding: 10px 15px 10px 15px; color: #000000;">               <p>Some content here</p>               <span style="font-weight: bold;">My Signature</span><br/>               My Title<br/>               My Company<br/>             </td>           </tr>         </table>       </td>     </tr>   </table> </div> 

The table will be exactly 700px wide is what is needed. However, because its entirely fixed width, it can't resize on devices with less than 700px width. But if I modify the td element to this:

<td style="max-width: 700px; width: 90%; padding: 10px 15px 10px 15px; color: #000000;">    <p>Some content here</p>    <span style="font-weight: bold;">My Signature</span><br/>    My Title<br/>    My Company<br/> </td> 

Then the table is only ~100px wide.

How would I reorder the CSS to make it so that the table is 700px but resizes as the viewport grows smaller?

like image 397
Noah Goodrich Avatar asked Sep 27 '13 07:09

Noah Goodrich


People also ask

How do I change the width to 100% in CSS?

It seems like this should be one of the easiest things to understand in CSS. If you want a block-level element to fill any remaining space inside of its parent, then it's simple — just add width: 100% in your CSS declaration for that element, and your problem is solved.

How do I limit the width of a table in CSS?

The best possible solution for this is the one you are using now. Since you cannot predict the number of columns you cannot set a width to each column. So setting the overflow of the parent div to auto and the child table width to 100% is the best solution.

How do you change the width of the table to 100 percent of the page width?

Click inside the table. On the menu, select Table > AutoFit > AutoFit to Window.

What is Max-Width 100 in CSS?

"width" is a standard width measurement for defining the exact width of an element. Defining "width:100%" means that the width is 100%. Defining "max-width:100%" means that the width can be anywhere between 0% and 100% but no more then 100%.


Video Answer


1 Answers

You need to use:

table{    width:100%;    table-layout: fixed;    overflow-wrap: break-word; } 

Demo

like image 115
Pablo Avatar answered Sep 29 '22 12:09

Pablo