我正在尝试在页眉中的徽标和菜单之间放置各种空间,使用display:flex
然后使用justify-content: flex-end
设置菜单,使用flex-start
设置徽标,但这不起作用。
我在标头上使用display: flex
和align-items:center
使标头上的所有元素对齐。但是现在我必须将菜单放在最后,将徽标放在开始。
html, body {
margin: 0;
padding: 0;
height: 100%;
}
header {
height: auto;
display: flex;
align-items: center;
}
a{
text-decoration: none;
}
nav ul.BarMenu {
background:#fff;
list-style-type: none;
display: flex;
}
nav ul.BarMenu a{
margin: 0 1em 0 1em;
color: black;
font-size: 13px;
border-bottom: 1px solid rgba(119, 87, 247, 0);
}
nav ul a:hover {
border-bottom: 1px solid rgba(119, 87, 247, 1);
}
<!DOCTYPE html>
<html>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<title>Title</title>
</head>
<body>
<header class="header" role="banner">
<div class="logo-holder">
<a href="#"><h1 class="logo">LOGO</h1></a>
</div>
<nav>
<ul class="BarMenu">
<a href="#"><li>text</li></a>
<a href="#"><li>text</li></a>
<a href="#"><li></li>text</a>
<a href="#"><li>text</li></a>
<a href="#" class="Start"><li>text</li></a>
</ul>
</nav>
</header>
</body>
</html>
答案 0 :(得分:0)
在标题中添加justify-content: space-between;
。
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
header {
height: auto;
display: flex;
align-items: center;
justify-content: space-between;
}
a {
text-decoration: none;
}
nav ul.BarMenu {
background: #fff;
list-style-type: none;
display: flex;
}
nav ul.BarMenu a {
margin: 0 1em 0 1em;
color: black;
font-size: 13px;
border-bottom: 1px solid rgba(119, 87, 247, 0);
}
nav ul a:hover {
border-bottom: 1px solid rgba(119, 87, 247, 1);
}
<!DOCTYPE html>
<html>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<title>Title</title>
</head>
<body>
<header class="header" role="banner">
<div class="logo-holder">
<a href="#">
<h1 class="logo">LOGO</h1>
</a>
</div>
<nav>
<ul class="BarMenu">
<a href="#">
<li>text</li>
</a>
<a href="#">
<li>text</li>
</a>
<a href="#">
<li></li>text</a>
<a href="#">
<li>text</li>
</a>
<a href="#" class="Start">
<li>text</li>
</a>
</ul>
</nav>
</header>
</body>
</html>
答案 1 :(得分:0)
您只需要这样写:
header {
display: flex;
justify-content: space-between;
}
答案 2 :(得分:0)
@Khalil Karim:希望能有所帮助!
html, body {
margin: 0;
padding: 0;
height: 100%;
}
header {
/* height: auto; */
display: flex;
align-items: center;
justify-content: space-between;
}
a{
text-decoration: none;
}
nav ul.BarMenu {
background:#fff;
list-style-type: none;
display: flex;
}
nav ul.BarMenu a{
display: flex;
/* margin: 0 1em 0 1em; */
color: #000000;
font-size: 13px;
border-bottom: 1px solid rgba(119, 87, 247, 0);
padding: 0 20px;
align-items: center;
margin: 0;
}
nav ul a:hover {
border-bottom: 1px solid rgba(119, 87, 247, 1);
}
<!DOCTYPE html>
<html>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<title>Title</title>
</head>
<body>
<header class="header" role="banner">
<div class="logo-holder">
<a href="#"><h1 class="logo">LOGO</h1></a>
</div>
<nav>
<ul class="BarMenu">
<a href="#"><li>Home</li></a>
<a href="#"><li>About Us</li></a>
<a href="#"><li></li>Services</a>
<a href="#"><li>Blog</li></a>
<a href="#" class="Start"><li>Contact Us</li></a>
</ul>
</nav>
</header>
</body>
</html>