css - CSS 未按预期呈现
问题描述
我有以下风格Calculator.css
.front {
display: flex;
justify-content: center;
text-align: center;
align-items: center;
height: 100vh;
width: 100%;
}
.calc-wrapper {
width: 400px;
height: 600px;
}
.row {
display: flex;
text-align: center;
width: 100%;
}
当我将它导入我的组件时Calculator.jsx
:
import "./css/Calculator.css";
...
render() {
return (
<div className="front">
<div className="calc-wrapper">
<Input input={this.state.input} />
<div className="row">
<Button>4</Button>
<Button>5</Button>
<Button>6</Button>
</div>
</div>
</div>
);
}
正如预期的那样,它连续显示三个按钮:
现在我将这个组件翻转到另一个,Field.jsx
.
字段.css
.back {
display: flex;
justify-content: center;
text-align: center;
align-items: center;
height: 100vh;
width: 100%;
}
.field-wrapper {
width: 400px;
height: 600px;
}
.field-row {
display: flex;
width: 100%;
}
并使用相同的逻辑Field.jsx
import "./css/Field.css";
...
render() {
const { items } = this.props;
return (
<div className="back">
<div className="field-wrapper">
<Output output={this.props} />
<div className="field-row">
<Position>{items[0]}</Position>
<Position>{items[1]}</Position>
<Position>{items[2]}</Position>
</div>
</div>
);
}
我正在水平显示项目...
位置.css
.position-wrapper {
height: 4em;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
font-weight: lighter;
font-size: 1.4em;
background-color: #e0e1e6;
color: #888888;
flex: 1;
outline: 1px solid #888888;
}
.field {
background-color: #fe9241;
color: #ffffff;
}
位置.jsx
import React from "react";
import "./css/Position.css";
const isOperator = val => {
return !isNaN(val) || val === "." || val === "=";
};
export const Position = props => (
<div
className={`position-wrapper ${
isOperator(props.children) ? null : "field"
}`}
onClick={() => props.handleClick(props.children)}
>
{props.children}
</div>
);
我错过了什么?
解决方案
尝试将属性:添加flex-direction:row;
到项目
.field-row {
display: flex;
flex-direction: row;
width: 100%;
}
.back {
display: flex;
flex-direction: row;
justify-content: center;
text-align: center;
align-items: center;
height: 100vh;
width: 100%;
}
推荐阅读
- arrays - 封闭范围数组
和反向收集 > - iis - 使用 ColdFusion 重写 IIS URL 会保留重复的字符串
- jquery - jQuery 更改只工作两次
- python - 等待断言变为真,并超时?
- multithreading - macOS 是否使用空闲线程进行调度?如果是这样,我如何监控其统计数据?
- date - 根据Google表格中的当前日期和时间选择“时间描述”(VLookup,Query)
- python - 有没有办法在 python 基础 docker 映像中安装 Firebase CLI?
- python - 我的素数列表中的 3 在哪里附加?
- javascript - 我如何从文本区域进行问题预览,如 Stack Overflow 上的
- python - 使用python导入不同的文件