[英]Aligning the navigation bar with logo
I'm trying to align my navigation menu but can't get it to work. 我正在尝试调整导航菜单,但无法正常使用。 What I want is - on the left side I want a small logo which also is a link that links to the start-page.
我想要的是-在左侧我想要一个小徽标,它也是一个链接到起始页的链接。 And in the middle of the webbsite I want the other "text-links" to be.
在网站的中间,我希望其他“文本链接”成为。 Like this
像这样
Here is the code and how it looks at the moment. 这是代码及其当前外观。 https://jsfiddle.net/oliha089/wh1zwg4x/ The logo is not at the left and the text is not in the middle of the website.
https://jsfiddle.net/oliha089/wh1zwg4x/徽标不在左侧,文本也不在网站中间。
HTML 的HTML
<header>
<div class = "menu" >
<ul>
<li> <a id = "logobut" href = "start-page.html">
<!-- försök flytta loggan till vänster kanten -->
<img id = "logoalign" src = "logga8svart.jpg" /> </a> </li>
<li> <a id = "portf" href = "portfolio-page.html"> PORTFOLIO </a> </li>
<li> <a id = "about" href = "aboutme-page.html"> ABOUT </a> </li>
<li> <a id = "contact" href = "contactme-page.html"> CONTACT </a> </li>
</ul>
</div>
</header>
CSS 的CSS
/* menu CSS-code */
.menu ul{
list-style: none;
z-index: 999;
background-color: white;/*#444;*/
text-align: center;
padding: 0;
margin: 0;
position: fixed;
width: 100%;
opacity: 0.7;
height: 50px;
}
.menu a:hover {
text-decoration: underline;
opacity: 1;
}
.menu a.active {
background-color: #fff;
color: #444;
cursor: default;
}
.menu a {
opacity: 0.7;
text-decoration: none;
font-weight: bold;
color: black; /*#fff;*/
display: block;
transition: background-color;
margin-left: 20px;
margin-right: 20px;
}
#logobut {
margin-right: 100px;
}
.menu li {
font-family: 'Oswald', sans-serif;
font-size: 1.2em;
line-height: 40px;
height: 40px;
border-bottom: 1px solid #888;
display: inline-block;
}
@media screen and (min-width: 600px) {
.menu li {
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 1.2em;
}
#logoalign {
height: 40px;
vertical-align: middle;
}
Thanks. 谢谢。
Here you go 干得好
Css 的CSS
/* menu CSS-code */
.menu ul{
list-style: none;
z-index: 999;
background-color: white;/*#444;*/
text-align: center;
padding: 0;
margin: 0;
position: fixed;
width: 100%;
opacity: 0.7;
height: 50px;
}
.menu a:hover {
text-decoration: underline;
opacity: 1;
}
.menu a.active {
background-color: #fff;
color: #444;
cursor: default;
}
.menu a {
opacity: 0.7;
text-decoration: none;
font-weight: bold;
color: black; /*#fff;*/
display: block;
transition: background-color;
margin-left: 20px;
margin-right: 20px;
}
#logobut {
margin-right: 100px;
}
.menu li {
font-family: 'Oswald', sans-serif;
font-size: 1.2em;
line-height: 40px;
height: 40px;
border-bottom: 1px solid #888;
display: inline-block;
}
@media screen and (min-width: 600px) {
.menu li {
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 1.2em;
}
#logoalign {
height: 40px;
vertical-align: middle;
}
.logoleft{
float:left;
}
HTML 的HTML
<header>
<div class = "menu" >
<ul>
<li class="logoleft"> <a id = "logobut" href = "start-page.html">
<!-- försök flytta loggan till vänster kanten -->
<img id = "logoalign" src = "logga8svart.jpg" /> </a> </li>
<li> <a id = "portf" href = "portfolio-page.html"> PORTFOLIO </a> </li>
<li> <a id = "about" href = "aboutme-page.html"> ABOUT </a> </li>
<li> <a id = "contact" href = "contactme-page.html"> CONTACT </a> </li>
</ul>
</div>
</header>
Here is an example with flex box and without lists: 这是一个带有弹性框但没有列表的示例:
nav { display: flex; width: 100%; background-color: grey; padding-left: 10px; justify-content: space-between; } .navPoints { display: flex; padding-left: 5px; } span { padding: 10px; font-family: Arial; } span:hover { cursor: pointer; color: white; }
<nav> <img src="https://www.google.ch/search?q=logo&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjp4vKH9qnNAhXD0RQKHZMHCaMQ_AUICCgB&biw=1600&bih=1085#imgrc=as8oG3SG3wToVM%3A"> <div class="navPoints"> <span>PORTFOLIO</span> <span>ABOUT</span> <span>CONTACT</span> </div> <div></div> </nav>
With flex box you can put something in a row like you would it do with float, but it's much easier and you have different ways to place it where you want. 使用flex box,您可以像放置float一样连续放置某些东西,但是它要容易得多,并且您可以通过不同的方式将其放置在所需的位置。 Check this guide: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
检查此指南: https : //css-tricks.com/snippets/css/a-guide-to-flexbox/
So it's really easy. 因此,这真的很容易。 I took a random logo for make the example.
我以随机徽标为例。
EDIT: Adding the links around in case of a span that should'nt be a problem for you :) 编辑:在跨度的情况下添加链接,这对您来说应该不是问题:)
Cheers. 干杯。
Add this, 加上这个
.menu{
width:100%;
}
.menu ul{
background-color: white;/*#444;*/
text-align: center;
padding-left: 0;
margin: 0;
width: 100%;
opacity: 0.7;
height: 50px;
float:left;
}
.menu ul li{
list-style-type:none;
display:inline-block;
padding-left: 20px;
padding-right: 20px;
float:left;
}
.menu a:hover {
text-decoration: underline;
opacity: 1;
}
.menu a.active {
background-color: #111;
color: #444;
cursor:pointer;
}
.menu a {
opacity: 0.7;
text-decoration: none;
font-weight: bold;
color: black; /*#fff;*/
transition: background-color;
}
#logobut {
padding-right: 20px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.