changing font size of material-ui buttons, and having the buttons scale?

旧时模样 提交于 2019-12-08 17:22:54

问题


I seem to be having an issue with changing the font sizes on Material-UI's (for React) RaisedButton and having the button itself scale properly with it.

<RaisedButton
label={<span className="buttonText">Log in Here</span>}
/>

CSS:

.buttonText {
    font-size: 63px;
}

The text size changes but the button itself doesn't scale with it. Does anyone know the proper solution to this? I want to button to scale with the text size.


回答1:


The problem is Material-UI inlines all of the styles for their components, so if you try to override them with CSS selectors it doesn't usually work quite right. Instead, try overriding whatever inline styles you don't want using the style property directly on the component. It would look something like this:

<RaisedButton style={{ fontSize: '63px' }} label='Log in Here' />

And if it still doesn't look quite right, just inspect all the generated inline styles on that component and see what you'd like to change, then just add that to the style object as well.

http://www.material-ui.com/#/components/raised-button




回答2:


Use the labelSize prop to override the inline style for the element

http://www.material-ui.com/#/components/raised-button

<RaisedButton
    label="Button" 
    labelStyle={{ fontSize: '63px'}}
/>



回答3:


<RaisedButton
   label="Label" 
   labelStyle={{ fontSize: 15 }}
/>



回答4:


It needs to be added with lineHeight as a style prop for even spacing:

  < RaisedButton style = {{lineHeight: '100px'}}
    label = 'lineHeight in style' / >

Here's a fiddle with all of the different solutions: https://jsfiddle.net/botbotdotdot/kfph5cc2/

Cheers




回答5:


Use font-size unit as Percent (%) or em. For e.g font-size:12%



来源:https://stackoverflow.com/questions/38209780/changing-font-size-of-material-ui-buttons-and-having-the-buttons-scale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!