html - 我想把它放在屏幕的中间中心,我想让 div 标签成为子元素的大小
问题描述
当我向图像添加绝对值时,图像居中。
我想用 div 标签将图像标签和 ap 标签居中,并且我希望 div 标签以绝对居中,但它不居中
import { FunctionComponent } from 'react';
const Index: FunctionComponent = () => {
return (
<>
<img
src="profile.svg"
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
margin: 'auto',
}}
/>
</>
);
};
export default Index;
const Index: FunctionComponent = () => {
return (
<>
<div
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
margin: 'auto',
}}
>
<img src="profile.svg" />
<p>name</p>
</div>
</>
);
};
export default Index;
解决方案
尝试给你的 div 一个 with 然后这样做:
width: 80vw;
left: 50%;
margin-left: -40vw;
推荐阅读
- ios - 如何让 Google 的 PlacePicker 在 iOS 上运行?
- regex - 如何使用 Bash 从 JSON 字符串中删除 \n 和 \r?
- android - 如何修复“不变对象作为反应子项无效”
- c++ - 尝试在数组中查找平均值时获取 -nan(ind) 输出(c++)
- java - ARCore中_ShowAndroidToastMessage()的作用是什么?
- r - 将列名称更改应用于数据框列表,但更改未反映在原始数据框中
- mysql - MySQL中的两个选择错误“每个派生表必须有自己的别名”?
- haskell - 如何在 Haskell 中编写模式准引用器?
- kotlin - Kotlin 类扩展
- angular - ionic 4 解析和提取 html 页面