如何使用材料ui在屏幕的右下侧添加浮动操作按钮

时间:2017-06-12 10:52:57

标签: html css reactjs material-ui

我正在尝试在屏幕的右下方添加FloatingActionButton。我正在使用此库http://www.material-ui.com/#/components/floating-action-button

import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";

import AppBar from "material-ui/AppBar";
import FloatingActionButton from "material-ui/FloatingActionButton";
import MuiThemeProvider from "material-ui/styles/MuiThemeProvider";
import * as strings from "./Strings";
import styles from "./Styles";
import ContentAdd from "material-ui/svg-icons/content/add";

const AppBarTest = () =>
  <AppBar
    title={strings.app_name}
    iconClassNameRight="muidocs-icon-navigation-expand-more"
  />;

class App extends Component {
  render() {
    return (
      <MuiThemeProvider>
        <div>
          <AppBarTest />
          <FloatingActionButton style={styles.fab}>
            <ContentAdd />
          </FloatingActionButton>
        </div>

      </MuiThemeProvider>
    );
  }
}

export default App;

Styles.js

const style = {
    fab: {
        backgroundColor: '#000000'
    },
};

export default style;

问题1

它在左上角显示FloatingActionButton,我想在右下方显示FloatingActionButton。这样做的方法是什么?

问题2

为什么样式不适用于{{1}}?

enter image description here

1 个答案:

答案 0 :(得分:5)

试试这种风格:

const fabStyle = {
    right: 20,
    position: 'fixed'
};

以后你使用margin,top ...但不要在position: fixed上使用auto