html - 为什么这个边距在这里?
问题描述
我正在制作个人资料卡,并在 div(.profile-card) 中制作了 div(.pic) 以让用户显示他们的个人资料照片。我在 .pic 的右边发现了奇怪的边距你知道为什么吗?
body {
height: 100vh;
background-color: #40407a;
padding: 0;
margin: 0;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.profile-card {
background-color: #2c2c54;
display: inline-block;
padding: 30px 40px;
text-align: center;
}
.pic {
width: 50px;
height: 50px;
border: 1px solid #33d9b2;
border-radius: 50%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="profile-card">
<div class="pic">
</div>
<div class="name">
<span>Name here</span>
</div>
</div>
</body>
</html>
解决方案
只是用来margin: auto;
把它放在中心。
body {
height: 100vh;
background-color: #40407a;
padding: 0;
margin: 0;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.profile-card {
background-color: #2c2c54;
display: inline-block;
padding: 30px 40px;
text-align: center;
}
.pic {
width: 50px;
height: 50px;
border: 1px solid #33d9b2;
border-radius: 50%;
margin: auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="profile-card">
<div class="pic">
</div>
<div class="name">
<span>Name here</span>
</div>
</div>
</body>
</html>
推荐阅读
- sed - 如何替换以文件中某些内容开头的行的第二次出现
- typescript - 如何使用 storybook 和 lerna 在 NPM 上创建和发布多个 Vuejs 组件?
- angular - 模板驱动的表单不起作用..“错误:未找到名称 'ngForm' 的导出”
- kivy - 无法从 Kivy 中的 io.BytesIO 加载图像
- css - 如何在css中使用flex进行溢出自动
- postgresql - 字段的长度对于正则表达式查找是否重要?索引是否有助于加快正则表达式查询?
- ruby-on-rails - 无法在 bitbucket 上使用 ssh 进行连接
- awk - 编写好的 awk begin 标头的问题
- android - lsetfilecon 失败:传输端点不支持操作
- javascript - antd PageHeader 样式未加载到我的 React 组件中