【发布时间】:2020-02-07 12:01:00
【问题描述】:
你能告诉我为什么 div 的宽度不占总宽度的 90% 吗?当我这样写的时候
width: 90%;
margin: 0 auto;
它需要宽度,但是当我这样写时它不会
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
这是我的代码
https://codesandbox.io/s/bitter-dawn-o6rx2
const Wrapper = styled.div`
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: "90%";
/* // width: 90%;
margin: 0 auto; */
`;
如何使表格垂直和水平居中
【问题讨论】:
-
它需要 90% 的宽度,你需要先检查 div 的样式。
-
我认为您的包含 div 应该首先具有定义的宽度,然后其中的包装器将占用该父 div 的 90% 的宽度。所以尝试先定义容器的宽度,然后再定义它的子容器( Wrapper )
-
你可以像
style={{Width: "90%", display: "flex",justifyContent: "center",alignItems: "center", height: "100vh" }}这样使用内联CSS作为对象 -
如何
center form vertically and horizontally -
"90%" 应该是 90%
标签: javascript css reactjs flexbox styled-components