html - 为什么“你好”不去左上角?
问题描述
我想在左上角创建一个菜单栏,其中每个按钮只是一个单词,但我无法让单词转到屏幕的左上角。我不知道它是否与 flexbox 有关...有什么建议吗?
.left-side {
background: white;
width: 50%;
height: 100%;
left: 0;
bottom: 0;
color: black;
position: absolute;
}
.right-side {
background: black;
width: 50%;
height: 100%;
right: 0;
bottom: 0;
color: white;
position: absolute;
}
.left-side,
.right-side {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
}
h1 {
font-size: 72px;
font-weight: 700;
}
p {
font-size: 48px;
font-weight: 300;
}
#navbar {
color: black;
width: auto;
float: left;
top: 0;
}
<div class="left-side">
<p id="navbar">Hello</p>
<h1>Welcome.</h1>
<p>I want to welcome you!</p>
</div>
<div class="right-side">
<h1>Corey M.</h1>
<p>Corey is my name :)</p>
</div>
解决方案
您可以position: absolute
像这样使用“hello”来定位:
#navbar {
color: black;
width: auto;
position: absolute;
margin: 0;
left: 20px;
top: 20px;
}
请参阅此处的工作示例:https ://jsfiddle.net/n75cqgo3/
推荐阅读
- python - Python 3.7 for Mac 默认安装在哪里?
- javascript - 如何在python中使用selenium获取包含在HTML标签中的html文档
- mysql - Mysql - 批量插入超过 50 万行
- .net - 为什么正则表达式不匹配字符串的最后一部分?
- django - 从热图上的 D3.js onclick 事件调用 Django View
- javascript - 将 then 的值保存在 Promise 之外的变量中
- javascript - 反应:useEffect vs useMemo vs useState
- opencv - 如何将图像文件堆叠到一个文件中以及如何调整黑白图像的大小
- amazon-s3 - 标记用glueContext.write_dynamic_frame 编写的s3 对象
- javascript - 将项目添加到数组中 - 单独