我开始接触glamorous,它是一个React 组件样式模块。我有两个要设置样式的按钮:Add
和Clear
. 我试图将两个按钮放在同一行,Clear
左侧的Add
按钮和右侧的按钮。我无法在同一行上制作两个按钮。相反,Clear
按钮位于按钮下方Add
。这就是我所拥有的:
import * as React from "react";
import glamorous from "glamorous";
import { CSSProperties } from "glamorous/typings/css-properties";
import { graphql, InjectedGraphQLProps } from "react-apollo";
import { reduxForm, Field, FormProps, WrappedFieldProps } from "redux-form";
import { ItemListQuery, AddItemMutation, AddItemMutationVariables } from "../queries/types";
const Form = glamorous.form({
display: "flex",
flexFlow: "column nowrap",
maxWidth: 320,
"> *": { margin: "1 1 30px" }
});
const Label = glamorous.label({
display: "flex",
flexFlow: "column-reverse",
"> :first-child": { marginTop: 5 }
});
const sharedInputStyles: CSSProperties = {
backgroundColor: "#e9e9e9",
border: "none",
borderBottom: "2px solid #e9e9e9",
padding: 6,
outline: "none",
transition: "all .2s ease-in",
":focus": {
borderBottom: "2px solid #777",
},
fontSize: 14,
fontWeight: 200
};
const ItemInput = glamorous.input(
sharedInputStyles,
{ height: 24 }
);
const Button = glamorous.button({
height: 40,
backgroundColor: "#bababa",
border: "none",
outline: "none",
":focus": { border: "2px solid #777" },
":active": {
backgroundColor: "#fff",
border: "2px solid #dcdcdc"
}
});
const ItemField = ({ input }: WrappedFieldProps<{}>) => (
<ItemInput {...input} />
);
export interface AddItemProps extends
InjectedGraphQLProps<{}>,
FormProps<Partial<Item>, undefined, undefined> {
}
const AddItem = ({ handleSubmit }: AddItemProps) => (
<Form onSubmit={handleSubmit}>
<Label>
Name
<Field name="name" component={ItemField} />
</Label>
<Button type="submit">Submit</Button>
<Button type="submit">Reset</Button>
</Form>
);
我尝试display: "inline"
像这样添加到 Button 组件:
const Button = glamorous.button({
height: 40,
backgroundColor: "#bababa",
display: "inline",
border: "none",
outline: "none",
":focus": { border: "2px solid #777" },
":active": {
backgroundColor: "#fff",
border: "2px solid #dcdcdc"
}
});
它没有做任何事情。接下来,我尝试将其更改为display: "inline-block"
:
const Button = glamorous.button({
height: 40,
backgroundColor: "#bababa",
display: "inline-block",
border: "none",
outline: "none",
":focus": { border: "2px solid #777" },
":active": {
backgroundColor: "#fff",
border: "2px solid #dcdcdc"
}
});
最后,我尝试overflow: "auto"
在 Button 组件中添加:
const Button = glamorous.button({
height: 40,
backgroundColor: "#bababa",
display: "inline-block",
overflow: "auto",
border: "none",
outline: "none",
":focus": { border: "2px solid #777" },
":active": {
backgroundColor: "#fff",
border: "2px solid #dcdcdc"
}
});
它也没有奏效。我所有的尝试都没有对按钮做任何事情。如何将按钮放在表单上均匀分布的同一行上?