html - 如何对齐 html 中的所有项目右边的元素?
问题描述
我在那里有这个 div,我将其用作菜单栏。我想将其中的所有项目都对齐到右侧,但我无法做到这一点。这是它的代码:
$(document).ready(function() {
$(window).scroll(function() {
if ($(document).scrollTop() > 20) {
$("#menubar").css('background', 'rgba(62, 63, 64, 0.88)');
$("#menubar a").css('color', 'white');
} else {
$("#menubar").css('background', '');
$("#menubar a").css('color', '');
}
});
});
#menubar a {
padding-top: 2vh;
padding-bottom: 2vh;
text-decoration: none;
color: #1A1A1A;
font-size: 2.5vh;
font-family: "Input Mono";
display: block;
float: left;
padding-right: 10px;
padding-left: 10px;
}
#menubar {
right: 0%;
position: fixed;
top: 0;
z-index: 999999;
overflow: hidden;
width: 100%;
}
<div id="menubar">
<a href="./index.html">Home</a>
<a href="href">About</a>
<a href="./index.html">Features</a>
<a href="./index.html">Download</a>
<a href="href">Github</a>
</div>
非常感谢您的帮助!
解决方案
像这样 ?:
$(document).ready(function() {
$(window).scroll(function() {
if ($(document).scrollTop() > 20) {
$("#menubar").css('background', 'rgba(62, 63, 64, 0.88)');
$("#menubar a").css('color', 'white');
} else {
$("#menubar").css('background', '');
$("#menubar a").css('color', '');
}
});
});
#menubar a {
padding-top: 2vh;
padding-bottom: 2vh;
text-decoration: none;
color: #1A1A1A;
font-size: 2.5vh;
font-family: "Input Mono";
display: block;
float: left;
padding-right: 10px;
padding-left: 10px;
}
#menubar {
right: 0%;
position: fixed;
top: 0;
z-index: 999999;
overflow: hidden;
width: 100%;
display: flex;
justify-content: flex-end;
}
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<div id="menubar">
<a href="./index.html">Home</a>
<a href="link">About</a>
<a href="./index.html">Features</a>
<a href="./index.html">Download</a>
<a href="link">Github</a>
</div>
推荐阅读
- sql - 逗号分隔列表oracle sql
- django - 随机字符串不是随机的
- postgresql - Postgres查找DML触发器中修改了哪些表
- c# - 读取 SQL Server 跟踪时引发异常
- linux - 使用“tar czf”和“tar + gzip”进行组合和压缩。两种情况下的结果文件都是 packname.tar.gz 但为什么大小不同?
- javascript - 从 React 中 Router Link 打开的新标签页更新主页状态
- node.js - Express 在根路径中添加了一个斜杠,这会破坏严格的路由
- reactjs - React.FC 中的 GenericType
> - javascript - 使用 jquery 分页插件进行分页
- here-api - 如何从 HERE Api 获取带有堵塞信息的区域、道路?