reactjs - 如何在页面中间放一个圆圈
问题描述
我在 App.css 中有一个 CSS 组件
.circle {
width: 100;
height: 100;
border-radius: 100/2;
background-color: red;
}
我想要的是将该组件放在页面中间。我怎样才能做到这一点 ?
import React from "react";
import "./App.css";
const App = () => {
return (
<div >
<div className="circle">
</div>
</div>
);
}
export default App;
解决方案
抛开反应,你可以使用 flexbox 来居中任何东西。你可以在 React 中实现相同的功能。
.circle {
width: 100px;
height: 100px;
background-color: cyan;
border-radius: 50%;
}
.container {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100vh;
}
<div class="container">
<div class="circle"></div>
</div>
推荐阅读
- algorithm - 我应该使用什么样的算法来解决这个圆桌问题?
- swiftui - 如果 SwiftUI 中没有子视图,则隐藏父视图?
- node.js - Stripe Webhook 验证
- regex - 与端线匹配的负向后看?
- python - asyncio 检查响应是否就绪的部分
- mysql - 根据多个日期时间字段中的最小日期时间获取记录
- perl - Log::Dispatch::FileRotate 是否将旋转文件的新/当前名称提供给 post_rotate 回调?
- javascript - 在全日历议程日获取不同的背景颜色
- pyspark - 菜鸟问题 pyspark - 获取所有列的最低/最高工资
- oracle - Oracle根据一列的值将多行分组为一个