简体   繁体   English

如何在Material UI中使背景图像响应

[英]How to make background-image responsive in Material UI

I'm trying to fix a problem with my background-image when I resize the browser. 当我调整浏览器大小时,我正在尝试修复背景图像的问题。 I have the background-image height on my application set to '100vh' which fills the entire page. 我的应用程序设置为'100vh'的背景图像高度填充整个页面。 When I resize the browser to a smaller width, the background image gets cut off. 当我将浏览器调整为较小的宽度时,背景图像会被切断。 Changing height to '100%' fixes this when the page is responsive BUT 100% shows the image cut off when I am back to regular desktop size because it only fills the background the size of the div. 当页面响应时,将高度更改为“100%”会修复此问题但是当我回到常规桌面大小时,100%会显示图像被切断,因为它只会填充div大小的背景。

I'm using Material UI. 我正在使用Material UI。 How would I go about responsively changing the background size? 我如何响应性地改变背景大小?

DOM DOM

return <main className={content}>                      

CSS CSS

content: {
    flexGrow: 1,
    padding: theme.spacing(3),
    height: '100vh',
    textAlign: 'center',
    backgroundImage: `url(${Background})`,
    backgroundRepeat: "no-repeat",
    backgroundPosition: "center center",
    backgroundSize: "cover",
    backgroundAttachment: "fixed",
  },

I tried adding this within my content style class but it didn't make a difference 我尝试在我的内容样式类中添加它,但它没有什么区别

[theme.breakpoints.down('lg')]: {
      height: '100%'
    }

Any suggestions? 有什么建议么? Thanks 谢谢

As such there is no class for responsive image, if you are searching for one, in material-ui. 因此,如果您正在搜索材料-ui,则没有响应式图像的类。 But you can try with the grid , container or breakpoint layouts. 但您可以尝试使用gridcontainerbreakpoint布局。
Please refer: 请参考:
https://material-ui.com/components/container/ https://material-ui.com/components/container/
https://material-ui.com/customization/breakpoints/ https://material-ui.com/customization/breakpoints/
https://material-ui.com/components/grid/ https://material-ui.com/components/grid/
https://material-ui.com/guides/responsive-ui/ https://material-ui.com/guides/responsive-ui/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM