gpt4 book ai didi

html - 顶部菜单 - 将一个元素右对齐

转载 作者:太空宇宙 更新时间:2023-11-04 01:05:17 25 4
gpt4 key购买 nike

我想将“登录”项右对齐。我对 HTML 和 CSS 很陌生。我什至不知道这是否是创建水平菜单栏的正确方法。像这样:How I want it to be

这是我的代码:

HTML:

@import url("FONTS/stylesheet.css");
body {
font-family: 'Roboto', sans-serif;
}

.topnav {
background-color: #333;
overflow: hidden;
}

.topnav a {
display: inline-block;
color: #f2f2f2;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}

.topnav a:hover {
background: #ddd;
color: black;
}

/* Add a color to the active/current link */
.topnav a.active {
background-color: #4CAF50;
color: white;
}
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="css/style1.css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<body>

<div class="topnav">
<a class="active" href="#home">Home</a>
<a href="#projects">Projects</a>
<a href="#contact">Contact</a>
<a class="loginnav" href="#login">Login</a>
</div>

</body>
</html>

我需要改变什么?非常感谢!

最佳答案

您只需将此代码添加到您的 CSS 中即可运行 .topnav .loginnav {float:right;}

@import url("FONTS/stylesheet.css");
body {
font-family: 'Roboto', sans-serif;
}

.topnav {
background-color: #333;
overflow: hidden;
}

.topnav a {
display: inline-block;
color: #f2f2f2;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}


.topnav a:hover {
background: #ddd;
color: black;
}

/* Add a color to the active/current link */
.topnav a.active {
background-color: #4CAF50;
color: white;
}
.topnav .loginnav {
float: right;
}
<!DOCTYPE html>
<html>

<link rel="stylesheet" type="text/css" href="css/style1.css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">

<body>

<div class="topnav">
<a class="active" href="#home">Home</a>
<a href="#projects">Projects</a>
<a href="#contact">Contact</a>
<a class="loginnav" href="#login">Login</a>
</div>

</body>
</html>

关于html - 顶部菜单 - 将一个元素右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52344709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com