我有一个包装纸,可以使所有内容居中:
const Wrapper = styled.div`
display: flex;
flex-direction: column;
align-items: center;
`;
但是由于某些原因,包装纸中具有最大宽度的align-items: center
组件会缩小。
如何在不触摸包装纸的情况下解决此问题?
CodeSandBox:https://codesandbox.io/embed/styled-components-qqkos
完整代码:
import React from "react";
import { render } from "react-dom";
import styled from "styled-components";
const Wrapper = styled.div`
display: flex;
flex-direction: column;
align-items: center;
`;
const Component = styled.div`
display: flex;
flex-direction: row;
`;
const Input = styled.input`
max-width: 1000px;
width: 100%;
`;
const Button = styled.button``;
const App = () => (
<Wrapper>
<Component>
<Input type="text" />
<Button>ClickMe</Button>
</Component>
</Wrapper>
);
render(<App />, document.getElementById("root"));
答案 0 :(得分:0)
好,问题可以这样解决:
const Component = styled.div`
display: flex;
flex-direction: row;
justify-content: center;
width: 100%;
`;