CSS 导航栏文字定位
CSS navbar text positioning
我正在寻找 2 天如何将导航栏上的“Login/Register”文本移动到导航栏的右侧,以便它与另一个 text/logo/spaced 在同一行以与徽标相同的方式使其保持一致(或移动徽标以使其卡在左侧)
我想post有点像这样:https://prnt.sc/10xtn19
徽标卡在左侧或间距很小,Home/Forums/Store 在我的导航栏中间居中,登录 + 注册在右侧,间距与徽标相同
* {
margin: auto;
padding: auto;
}
body {
min-height: 100vh;
background-color: #3e3e3e;
}
header {
background-color: rgba(15, 15, 15, 0.99)!important;
box-shadow: 0 5px 5px rgba(0, 0, 0, .3);
left: 50%;
padding: 10px 20px;
text-align: center;
opacity: 0.9;
}
.home {
padding: 10px 15px;
background: transparent;
border: none;
}
.home-a {
color: white;
text-decoration: none;
font-family: 'Nunito', sans-serif;
font-size: 17px;
}
.forums {
padding: 10px 15px;
background: transparent;
border: none;
}
.forums-a {
color: white;
text-decoration: none;
font-family: 'Nunito', sans-serif;
font-size: 22px;
}
.store {
padding: 10px 15px;
background: transparent;
border: none;
}
.store-a {
color: white;
text-decoration: none;
font-family: 'Nunito', sans-serif;
font-size: 18px;
}
.register {
padding: 10px 15px;
list-style-type: none;
padding-right: 15px;
text-align: center;
}
.register-a {
color: white;
text-decoration: none;
font-family: 'Nunito', sans-serif;
font-size: 17px;
}
.login {
padding: 10px 15px;
list-style-type: none;
text-align: center;
}
.login-a {
color: white;
text-decoration: none;
font-family: 'Nunito', sans-serif;
font-size: 17px;
}
.login-register {
justify-content: left;
}
.header-logo {
position: absolute;
top: 10px;
left: 10px;
width: 256px;
height: 50px;
padding-right: 500px;
}
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="main.css">
<link rel="icon" type="img/svg+xml" href="img/favicon.svg">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Nunito&display=swap" rel="stylesheet">
<title>Home | Kurium v4.5</title>
</head>
<body>
<header>
<ul class="kurium-button">
<img class="header-logo" src="img/logo.svg">
<button class="home"><a class="home-a" href="https://google.fr/">Home</a> </button>
<button class="forums"><a class="forums-a" href="https://google.fr/">Forums</a> </button>
<button class="store"><a class="store-a" href="https://google.fr/">Store</a> </button>
</ul>
<ul class="login-register">
<!-- A remplacer par : Flexbox -->
<li class="register" style="float:right"><a class="register-a" href="register.html">Register</a></li></button>
<li class="login" style="float:right"><a class="login-a" href="login.html">Login</a></li></button>
</ul>
</header>
</body>
</html>
Flex 太棒了!试试这个:
<header>
<div style="display: flex;">
<div style="width: 100%;">
<ul class="kurium-button">
<img class="header-logo" src="img/logo.svg">
<button class="home"><a class="home-a" href="https://google.fr/">Home</a> </button>
<button class="forums"><a class="forums-a" href="https://google.fr/">Forums</a> </button>
<button class="store"><a class="store-a" href="https://google.fr/">Store</a> </button>
</ul>
</div>
<div style="width: 20%;">
<ul class="login-register">
<!-- A remplacer par : Flexbox -->
<li class="register" style="float:right"><a class="register-a" href="register.html">Register</a></li></button>
<li class="login" style="float:right"><a class="login-a" href="login.html">Login</a></li></button>
</ul>
</div>
</div>
</header>
还有这个:
.login-register { display: flex; justify-content: center; }
并尝试掌握 flex 我的朋友。
我正在寻找 2 天如何将导航栏上的“Login/Register”文本移动到导航栏的右侧,以便它与另一个 text/logo/spaced 在同一行以与徽标相同的方式使其保持一致(或移动徽标以使其卡在左侧)
我想post有点像这样:https://prnt.sc/10xtn19 徽标卡在左侧或间距很小,Home/Forums/Store 在我的导航栏中间居中,登录 + 注册在右侧,间距与徽标相同
* {
margin: auto;
padding: auto;
}
body {
min-height: 100vh;
background-color: #3e3e3e;
}
header {
background-color: rgba(15, 15, 15, 0.99)!important;
box-shadow: 0 5px 5px rgba(0, 0, 0, .3);
left: 50%;
padding: 10px 20px;
text-align: center;
opacity: 0.9;
}
.home {
padding: 10px 15px;
background: transparent;
border: none;
}
.home-a {
color: white;
text-decoration: none;
font-family: 'Nunito', sans-serif;
font-size: 17px;
}
.forums {
padding: 10px 15px;
background: transparent;
border: none;
}
.forums-a {
color: white;
text-decoration: none;
font-family: 'Nunito', sans-serif;
font-size: 22px;
}
.store {
padding: 10px 15px;
background: transparent;
border: none;
}
.store-a {
color: white;
text-decoration: none;
font-family: 'Nunito', sans-serif;
font-size: 18px;
}
.register {
padding: 10px 15px;
list-style-type: none;
padding-right: 15px;
text-align: center;
}
.register-a {
color: white;
text-decoration: none;
font-family: 'Nunito', sans-serif;
font-size: 17px;
}
.login {
padding: 10px 15px;
list-style-type: none;
text-align: center;
}
.login-a {
color: white;
text-decoration: none;
font-family: 'Nunito', sans-serif;
font-size: 17px;
}
.login-register {
justify-content: left;
}
.header-logo {
position: absolute;
top: 10px;
left: 10px;
width: 256px;
height: 50px;
padding-right: 500px;
}
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="main.css">
<link rel="icon" type="img/svg+xml" href="img/favicon.svg">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Nunito&display=swap" rel="stylesheet">
<title>Home | Kurium v4.5</title>
</head>
<body>
<header>
<ul class="kurium-button">
<img class="header-logo" src="img/logo.svg">
<button class="home"><a class="home-a" href="https://google.fr/">Home</a> </button>
<button class="forums"><a class="forums-a" href="https://google.fr/">Forums</a> </button>
<button class="store"><a class="store-a" href="https://google.fr/">Store</a> </button>
</ul>
<ul class="login-register">
<!-- A remplacer par : Flexbox -->
<li class="register" style="float:right"><a class="register-a" href="register.html">Register</a></li></button>
<li class="login" style="float:right"><a class="login-a" href="login.html">Login</a></li></button>
</ul>
</header>
</body>
</html>
Flex 太棒了!试试这个:
<header>
<div style="display: flex;">
<div style="width: 100%;">
<ul class="kurium-button">
<img class="header-logo" src="img/logo.svg">
<button class="home"><a class="home-a" href="https://google.fr/">Home</a> </button>
<button class="forums"><a class="forums-a" href="https://google.fr/">Forums</a> </button>
<button class="store"><a class="store-a" href="https://google.fr/">Store</a> </button>
</ul>
</div>
<div style="width: 20%;">
<ul class="login-register">
<!-- A remplacer par : Flexbox -->
<li class="register" style="float:right"><a class="register-a" href="register.html">Register</a></li></button>
<li class="login" style="float:right"><a class="login-a" href="login.html">Login</a></li></button>
</ul>
</div>
</div>
</header>
还有这个:
.login-register { display: flex; justify-content: center; }
并尝试掌握 flex 我的朋友。