简体   繁体   English

如何在导航栏上排列文本?

[英]How do I arrange the text on the navigation bar?

I was wondering if anyone could help me with an issue I'm having. 我想知道是否有人可以解决我遇到的问题。 I wanted the text "Liam's Digital Portfolio" to be in the centre of the webpage at the top in line with the navigation bar text. 我希望文本“ Liam's Digital Portfolio”位于导航栏顶部的网页中央。 In addition, I then wanted the navigation bar to be on the far right hand corner as shown within the codepen link http://codepen.io/ldocherty1/pen/qRowVK . 另外,我然后希望导航栏位于代码笔链接http://codepen.io/ldocherty1/pen/qRowVK中所示的最右角。

I have only started programming and this is my second day and really want to improve, apologies if the code is not in the correct structure. 我才刚刚开始编程,这是我的第二天,如果代码的结构不正确,我真的想改进。

Below is my HTML code, within the codepen is my CSS if needed. 下面是我的HTML代码,如果需要,在代码笔内是我的CSS。

<div id="Navagationbar">
   <ul>
  <li><b><a href="#">HomePage</a></b></li>
  <li><b><a href="#">Portfolio</a></b></li>
  <li><b><a href="#">Contact Us</a></b></li>
  <li><b><center>Liam's Digital Portfolio<center></b></li>
   </ul>
 </div>
     </body>
</html>

Thanks, Liam. 谢谢,利亚姆。

I wish you all the best with your coding journey :) I will give you an easy solution to get the desired effect. 祝您在编码过程中一切顺利:)我将为您提供一个简单的解决方案,以取得理想的效果。 First off, cut the padding-top from the body in the css: 首先,从CSS的正文中剪切出padding-top:

padding-top: 180px;

Now from your html, remove 现在从您的html中删除

  <li><b><center>Liam's Digital Portfolio<center></b></li>

Since this is your page title, it is standard practice to have it inside of h1 tags. 由于这是您的页面标题,因此通常将其包含在h1标签中。 Then we can center it with simple css. 然后,我们可以使用简单的CSS将其居中。 The html will look like this: HTML将如下所示:

<h1 class="title">Liam's Digital Portfolio</h1>       

<div id="Navagationbar">
 <ul>
  <li><b><a href="#">HomePage</a></b></li>
  <li><b><a href="#">Portfolio</a></b></li>
  <li><b><a href="#">Contact Us</a></b></li>
 </ul>
</div>

And now we can simply add this to the css 现在我们可以简单地将其添加到css中

.title{text-align:center;}

With the padding-top removed and this added, the title will be in the center of the page inline with the navigation bar. 删除顶部填充并添加该顶部填充后,标题将位于导航栏内的页面中心。 I see you have a lot of issues with your css so I suggest you go through a good tutorial, like this one from w3schools http://www.w3schools.com/css/ . 我发现您的CSS存在很多问题,因此建议您阅读一个不错的教程,例如w3schools http://www.w3schools.com/css/上的教程。 I hope this helps, and good luck! 我希望这个帮助能祝你好运!

Make the HTML changes as below 进行如下的HTML更改

        <ul>
          <li><b><a href="#">HomePage</a></b></li>
          <li><b><a href="#">Portfolio</a></b></li>
          <li><b><a href="#">Contact Us</a></b></li>
          <li style="position:absolute;right:45%"><b><a href="#">Liam's Digital Portfolio</a></b></li>
       </ul>

CSS changes as below CSS更改如下

    ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;

}

li {
    float: left;
}

li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}



    h1 {
    font-family:Arial;
    color:white;
    font-size:10pt;
    text-align:center;
    }

    li a:hover:not(.active) {
    background-color:grey;
}

   #Navagationbar {
   font-family:Arial;
   color:white;
   font-size:10pt;
   text-align:center;

}

   #Navagationbar ul {
   list-style:none;
   float:right;
   margin:0;
   padding:0;

}
   #Navagationbar ul li {
   display:block;
   list-style:none;
   margin:0;
   padding:0;


}

#Navagationbar ul li a {
   display:block;
   margin:0 0 0 1px;
   padding:3px 10px;
   color:white;;
   text-decoration:none;
   line-height:1.3em;

}
#Navagationbar ul li a:hover {
   color:white;
}
#Navagationbar ul li a.active,
#Navagationbar ul li a.active:hover {
   color:white;

}

body {
  margin:0;
}
.page{
  min-height:-590px;
  background:linear-gradient(45deg, #999, #FFF);
}
#footer{
  list-style:none inside none;
  margin:0;
  padding:0;
  position:fixed;
  right:0;
  bottom:0;
  left:0;
  height:50px;
  background-color:#1f1f1f;
  font-size:0;
}
#footer li {
  font-family:Arial;
  float: right;
  color:white;
  font-size:10pt;
  display:inline-block;
  text-align:center;
  height:50px;
  padding:0 20px;
  line-height:3.3;
  border-right:1px solid #000;
  border-left:1px solid #333;
}
#footer li {
  font-family:Arial;
  float: left;
  color:white;
  font-size:10pt;
  display:inline-block;
  text-align:center;
  height:50px;
  padding:0 20px;
  line-height:3.3;
  border-right:1px solid #000;
  border-left:1px solid #333;
}


#footer li:last-child {
  border-right:0;
}

    body {
        background:url('https://static.pexels.com/photos/34088/pexels-photo.jpg');
            position:static;
            height:400px; 
            background-attachment:fixed;
            background-repeat:no-repeat;
            background-size:cover;

        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM