有人使用react.jsMaterial UI库创建网页吗?我应该如何调整图标大小?它是一个svg图标.

import React from 'react';
import Paper from 'material-ui/lib/paper';
import ContentAdd from 'material-ui/lib/svg-icons/content/add';
import IconButton from 'material-ui/lib/icon-button';


const styleForPaper = {
  width: '96vw',
  height: '20vh',
  margin: 20,
  textAlign: 'center',
  display: 'inline-block',
};

const styleForButton = {
  'marginTop': '7vh',
};


const PaperToAddNewWidgets = () => (
  <div>

    <Paper style={styleForPaper} zDepth={2}>

    <IconButton
        style={styleForButton}
        touch={true}
        tooltip="Add New Widget">

    <ContentAdd/>

    </IconButton>

    </Paper>
  </div>
);

export default PaperToAddNewWidgets;

它看起来没问题(请确保您以全尺寸查看),但图标太小.然后我打开chrome开发工具,看到了下面的html代码.

<div style="background-color:#ffffff;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;box-sizing:border-box;font-family:Roboto, sans-serif;-webkit-tap-highlight-color:rgba(0,0,0,0);box-shadow:0 3px 10px rgba(0,0,0,0.16),
         0 3px 10px rgba(0,0,0,0.23);border-radius:2px;width:96vw;height:20vh;margin:20px;text-align:center;display:inline-block;mui-prepared:;" data-reactid=".0.2.0.1.0"><button style="border:10px;background:none;box-sizing:border-box;display:inline-block;font:inherit;font-family:Roboto, sans-serif;tap-highlight-color:rgba(0, 0, 0, 0);cursor:pointer;text-decoration:none;outline:none;transform:translate3d(0, 0, 0);position:relative;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;padding:12px;width:48px;height:48px;font-size:0;margin-top:7vh;mui-prepared:;-webkit-appearance:button;" tabindex="0" type="button" data-reactid=".0.2.0.1.0.0"><div data-reactid=".0.2.0.1.0.0.0"><span style="height:100%;width:100%;position:absolute;top:0;left:0;overflow:hidden;mui-prepared:;" data-reactid=".0.2.0.1.0.0.0.0"></span><div style="position: absolute; font-family: Roboto, sans-serif; font-size: 14px; line-height: 32px; padding: 0px 16px; z-index: 3000; color: rgb(255, 255, 255); overflow: hidden; top: -10000px; border-radius: 2px; opacity: 0; left: -44px; transition: top 0ms cubic-bezier(0.23, 1, 0.32, 1) 450ms, transform 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms, opacity 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; box-sizing: border-box; -webkit-user-select: none;" data-reactid=".0.2.0.1.0.0.0.1:0"><div style="position: absolute; left: 50%; top: 0px; transform: translate(-50%, -50%); border-radius: 50%; transition: width 0ms cubic-bezier(0.23, 1, 0.32, 1) 450ms, height 0ms cubic-bezier(0.23, 1, 0.32, 1) 450ms, backgroundColor 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; width: 0px; height: 0px; background-color: transparent;" data-reactid=".0.2.0.1.0.0.0.1:0.0"></div><span style="position:relative;white-space:nowrap;mui-prepared:;" data-reactid=".0.2.0.1.0.0.0.1:0.1">Add New Widget</span></div><svg style="display:inline-block;height:24px;width:24px;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;fill:rgba(0, 0, 0, 0.87);mui-prepared:;-webkit-user-select:none;" viewBox="0 0 24 24" data-reactid=".0.2.0.1.0.0.0.1:2:$/=10"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" data-reactid=".0.2.0.1.0.0.0.1:2:$/=10.0"></path></svg></div></button></div>

使用chrome开发工具,我修改了svg图标大小和svg的viewbox属性,并在浏览器中放大了图标.但我不确定如何在代码中调整图标大小.如果我编写一个CSS文件来修改svg,那么如果有多个svg元素,就会出现问题.

推荐答案

Note:IconButtonmaterial UI上不再支持iconStyleprops ,因此此答案已过时

你必须在<IconButton>中设置iconStyleprops 中图标的大小.例如from the material-ui docs以下.

根据我的经验,如果你只设定高度或宽度,什么都不会发生——只有当你设定高度和宽度时,似乎才起作用;宽度设置为相同的值.

import React from 'react';
import IconButton from 'material-ui/IconButton';
import ActionHome from 'material-ui/svg-icons/action/home';

const styles = {

  largeIcon: {
    width: 60,
    height: 60,
  },

};

const IconButtonExampleSize = () => (
  <div>
    <IconButton
      iconStyle={styles.largeIcon}

    >
      <ActionHome />
    </IconButton>
  </div>
);

Reactjs相关问答推荐

使用React.lazy组件防止 children 在数据更改时重新加载

利用OVERPASS API端点计算某建筑的表面积

将对象添加到集合中的数组时的no_id字段

如何在MUI X数据网格列中显示IMG?

页面永远加载API/从数据库获取数据

在任何渲染之前在ReactJs中获取数据

状态改变不会触发重新渲染

react :输入失go 焦点,输入一个字符,

ReactJS 中的图像加载顺序

Zod 验证模式根据另一个数组字段使字段成为必需字段

使用 react pro 侧边栏展开折叠菜单

页面不显示

如何在react 中正确销毁上下文?

作为单个变量的 React 组件是否比 memoized 组件渲染得更快?

我如何在所有组件中使用 Chakra UI toast?

如果传递给挂钩的数据需要事先修改,如何使用自定义挂钩?

在 Reactjs 中状态发生变化时渲染一个新组件而不替换旧组件

列表应该有一个唯一的关键props

axios post方法中的请求失败,状态码为500错误

为什么我从另一个组件收到错误?