Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

material-ui: How to top the text in tablecell?

Tags:

material-ui

I have googled for many hours to find a solution, but it seems to be very difficult to vertically align text within a tablecell. I am confused as to why they make the horizontal alignment easy, while the vertical alignment is that difficult.

<TableCell colSpan={2} align='center' vertical-align='top' > 
    <Typography  variant="h5" gutterBottom > 
        Task
    </Typography> 
</TableCell>
like image 270
Yong123 Avatar asked Mar 19 '19 10:03

Yong123


People also ask

How do I align text to the top of a table?

To place an item at the top or bottom of its cell, insert the "VALIGN=" attribute within the code for that cell. To vertically align an entire row (e.g., placing all data in that row at the tops of the cells), insert the "VALIGN=" attribute within the code for that row.

How do I align text in material UI?

The Typography component of Material UI is used to present your text and content as clearly and efficiently as possible. Import: import Typography from '@material-ui/core/Typography'; // OR import { Typography } from '@material-ui/core'; Syntax: It sets the alignment property.

How do you align the text within a table's data cells so that the text is vertically centered HTML?

Add CSS. Set the border for the <table> and <td> elements. Add the height and width properties for the <td> tag. Set the text-align property to "center", and the vertical-align to "middle" for the <td> tag.


1 Answers

The TableCell component from material-ui doesn't provide such vertical-align prop, only align. To change vertical align of TableCell you have to pass a style prop (or a className), like that:

<TableCell colSpan={2} align="center" style={{ verticalAlign: 'top' }} > 
    <Typography  variant="h5" gutterBottom > 
        Task
    </Typography> 
</TableCell>

Any props that TableCell doesn't know is passed to it's children root (th element in this case), and in JSX you can pass a inline style with the prop style and a camelcased object.

like image 186
Pablo R. Dinella Avatar answered Oct 19 '22 02:10

Pablo R. Dinella