2017-06-12 9 views
1

画面の右下にFloatingActionButtonを追加しようとしています。私はhttp://www.material-ui.com/#/components/floating-action-button反応の材料uiを使用して画面の右下に浮動アクションボタンを追加する方法

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; 

それは左上側にFloatingActionButtonを示している1

質問、私は右下側にこれを作りたい、このライブラリを使用しています。これを行う方法は何ですか?

質問2

スタイルはFloatingActionButtonに適用されていないのはなぜ?

enter image description here

+0

にautoを使用していないあなたは、トップと左の自動削除しようとしたことがありスタイル?あなたのスタイルはstyles.jsからエクスポートされていますか? –

+0

@JeroenWienkスタイルが正しく設定されていないと思います。私も輸出しましたが、変化はありません。ここで何が間違っていますか? 'const fabStyle = { backgroundColor: '#000000' }; module.exports = fabStyle; ' –

+0

@JeroenWienk更新されたコードで質問が更新されましたを参照してください –

答えて

2

このスタイルを試してみてください:トップ、

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

以降uはマージンを使用...しかしposition: fixed

+0

backgroundColorが動作していない理由はありますかhttp://www.material-ui.com/#/components/floating -action-button残りのものは動作しています。私はこれを 'backgroundColor: '#000000'' –

+0

として設定しています。これを試してみてください:FloatingActionButton backgroundColor ='#CCC 'style = {styles.fab}>

+0

FloatingActionButtonは、背景色にURの小道具で設定:D –

関連する問題