如何将菜单内嵌与左侧的标题对齐?标题应该左边和右边的菜单对齐,但是当我尝试这样做时它会继续低于我的标题并且宽度很好。
* {
font-family: "freight-sans-pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 0;
margin: 0;
}
body {
background-color: #5fbf9a;
}
.header {
margin: auto;
width: 50%;
height: 130px;
background-color: #5fbf9a;
}
.header a:hover {
color: #000;
cursor: pointer;
}
.header p {
color: rgba(0, 0, 0, 0.5);
letter-spacing: 2px;
font-size: 18px;
text-transform: uppercase;
}
.header ul {
list-style-type: none;
font-size: 18px;
color: rgba(0, 0, 0, 0.5);
}
.header li {
display: inline;
}
a {
transition: 0.07s ease-in all;
text-decoration: none;
-webkit-transition: 0.07s ease-in all;
-moz-transition: 0.07s ease-in all;
-o-transition: 0.07s ease-in all;
color: rgba(0, 0, 0, 0.5);
}
.logo {
width: 200px;
line-height: 130px;
}
.menu {
width: 400px;
line-height: 130px;
}
.content {
background-color: #ffffff;
margin: auto;
width: 50%;
height: auto;
border-radius: 6px;
}
.footer {
width: 100%;
height: 130px;
background-color: #f0f5f7;
text-transform: uppercase;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blog</title>
<link rel="stylesheet" type="text/css" href="../stylesheets/test.css">
</head>
<body>
<div class="header">
<div class="logo">
<p><a href="www.lucafraser.nl" target="blank">Luca Fraser</a>
</p>
</div>
<div class="menu">
<ul>
<li>Work</li>
<li>About</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</div>
<!-- <div class="content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia.</p>
</div> -->
<!-- <div class="footer">
<h1>Made by Luca</h1>
</div> -->
</body>
</html>
答案 0 :(得分:0)
根据您的目标,这些CSS定义可以提供帮助:
.logo, .menu { float: left; } ;
或
.interface div {
display: inline-block;
width: 30%;
text-align: center;
padding: 10px;
margin-left: auto;
margin-right: auto;
}
.interface {
margin-left: auto;
margin-right: auto;
width: 50%;
text-align: center;
padding: 10px;
}
#board {
width: 90vw;
height: 90vw;
table-layout: fixed;
}
.boardSpace {
border-radius: 10px;
border: 5px solid black;
}
你可以谷歌找出差异。 如果您不熟悉css,请查看Bootstrap
您可以使用其导航栏,导航组件和网格系统轻松定位元素
答案 1 :(得分:0)
首先,从line-height
和.logo
中删除.menu
,然后添加:
header {
display: flex;
align-items: center;
justify-content: space-between
}
* {
font-family:"freight-sans-pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 0;
margin: 0;
}
body {
background-color: #5fbf9a;
}
.header {
margin: auto;
width: 50%;
height: 130px;
background-color: #5fbf9a;
display: flex;
align-items: center;
justify-content: space-between
}
.header a:hover {
color: #000;
cursor: pointer;
}
.header p {
color: rgba(0, 0, 0, 0.5);
letter-spacing: 2px;
font-size: 18px;
text-transform: uppercase;
}
.header ul {
list-style-type: none;
font-size: 18px;
color: rgba(0, 0, 0, 0.5);
}
.header li {
display: inline;
}
a {
transition: 0.07s ease-in all;
text-decoration: none;
-webkit-transition: 0.07s ease-in all;
-moz-transition: 0.07s ease-in all;
-o-transition: 0.07s ease-in all;
color: rgba(0, 0, 0, 0.5);
}
.logo {
width: 200px;
}
.menu {
width: 400px;
}
.content {
background-color: #ffffff;
margin: auto;
width: 50%;
height: auto;
border-radius: 6px;
}
.footer {
width: 100%;
height: 130px;
background-color: #f0f5f7;
text-transform: uppercase;
}
&#13;
<div class="header">
<div class="logo">
<p><a href="www.lucafraser.nl" target="blank">Luca Fraser</a></p>
</div>
<div class="menu">
<ul>
<li>Work</li>
<li>About</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</div>
&#13;
您会在演示中注意到,当窗口太小时,徽标会跳转到两行。您可以通过将
来防止这种情况发生flex-shrink: 0
添加到.logo