Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make table td taking up the whole width using css?

Tags:

html

css

I am making a site with tables mobile responsive. How do I make table td take up the whole full width(100%) using css?

<table>
    <tr>
        <td>Column One</td>
        <td>Column Two</td>
    </tr>
</table>

It is too hard to read information in two columns close to each other.

like image 555
Alex Avatar asked Jul 30 '13 21:07

Alex


People also ask

How do I fix td width in CSS?

By using CSS, the styling of HTML elements is easy to modify. To fix the width of td tag the nth-child CSS is used to set the property of specific columns(determined by the value of n) in each row of the table.

How do you make a full width occupy table?

You need to set the margin of the body to 0 for the table to stretch the full width. Alternatively, you can set the margin of the table to a negative number as well.

How do I get full width in CSS?

Using width, max-width and margin: auto; As mentioned in the previous chapter; a block-level element always takes up the full width available (stretches out to the left and right as far as it can). Setting the width of a block-level element will prevent it from stretching out to the edges of its container.

How do you make TD equal width?

Using table-layout: fixed as a property for table and width: calc(100%/3); for td (assuming there are 3 td 's). With these two properties set, the table cells will be equal in size.


1 Answers

This will show the cells one below the other:

td {display:block;width:99.9%;clear:both}

or, as noted by @nux,

td {display:block; box-sizing:border-box; clear:both}

either should be enough, although microsoft browser won't oblige and you might need proprietary markup for those; then again if people plan to use a browser on their phone they wouldn't buy a microsoft phone, so the problem is minor.

like image 128
Riccardo Zorn Avatar answered Sep 17 '22 16:09

Riccardo Zorn