Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MaterialUI: Paper or Card title

Designing a React application, what I want is having the title of a Card or Paper on the top border with some indention from left side, like this:

enter image description here

I searched a lot and couldn't find a generic way to do so. Should I create a customised component or there's way for this?

like image 644
Hans Avatar asked Jan 20 '19 00:01

Hans


Video Answer


1 Answers

I don't know exactly what you want it to look like, but you can achieve something like that by using the fieldset and legend elements.

It might look like this:

<fieldset>
  <legend>Current</legend>
  // Content within border.
</fieldset>

Result:

Example of fieldset

This approach is used by Material-UI for the "Outlined" variant of TextField (demo here). The code that handles this aspect is the NotchedOutline component (source here).

You can also fairly easily do something yourself via a position attribute to move a title element up over the border. This would actually allow you to use one of those material-ui components to provide most of the styles, and then just move the title on to the border.

Checkout this Codepen for an examples: https://codepen.io/codingmatty/pen/bOXKpZ

like image 110
Matty J Avatar answered Nov 15 '22 11:11

Matty J