仅导航

时间:2016-09-08 10:38:25

标签: html css navigation

我正处于学习网页开发的初级阶段。我想到了布局,并尝试为它提出代码。

我想在网站的右上角设置社交媒体导航。我想出了以下的HTML。

<nav class="snav">
<a href="#"><img src="../desktop/linked.png" height="32px" width="32px"></a>
<a href="#"><img src="../desktop/fb.png" height="32px" width="32px"></a>
<a href="#"><img src="../desktop/twitter.png" height="32px" width="32px"></a>
<a href="#"><img src="../desktop/google.png" height="32px" width="32px"></a>
</nav>

和css

.snav {
position: absolute;
top: 50px;
right: 50px;
}

.snav a {
    padding-right: 5px;
    padding-left: 5px;
}   

但是,屏幕上只显示谷歌+图标。

以下是该网站的完整代码。

body {
  background-image: url('../desktop/image.jpg');
  background-repeat: no-repeat;
  margin: 0;
}
.header {
  background-color: #fcfcfc;
  opacity: 0.5;
  max-width: 100%;
  height: 120px;
  border-bottom: 0.4px solid #bd0000;
  position: relative;
  top: 0;
}
.bar_1 {
  position: absolute;
  left: 0px;
  margin-left: 5%;
  margin-top: 80px;
  height: 50vh;
  width: 25%;
  background-color: #fcfcfc;
  opacity: 0.5;
  border-radius: 10px;
  border: 0.4px solid #bd0000;
}
.bar_2 {
  position: absolute;
  left: 38.33%;
  margin-top: 80px;
  height: 50vh;
  width: 23.33%;
  background-color: #fcfcfc;
  opacity: 0.5;
  border-radius: 10px;
  border: 0.4px solid #bd0000;
}
.bar_3 {
  position: absolute;
  left: 71.66%;
  margin-right: 5%;
  margin-top: 80px;
  height: 50vh;
  width: 23.33%;
  background-color: #fcfcfc;
  opacity: 0.5;
  border-radius: 10px;
  border: 0.4px solid #bd0000;
}
.bar_1:hover {
  background-color: #bd0000;
}
.bar_2:hover {
  background-color: #bd0000;
}
.bar_3:hover {
  background-color: #bd0000;
}
#footer {
  position: relative;
  top: 100vh;
  background-color: #fcfcfc;
  max-width: 100%;
  height: 70px;
  border-top: 0.4px solid #bd0000;
}
* {
  box-sizing: border-box;
}
.search_bar {
  position: absolute;
  top: 650px;
  left: 29%;
  right: 33.33%;
}
#search {
  border: 2px solid #bd0000;
  background-color: #fff;
  opacity: 0.5;
  font-color: #fcfcfc;
  font-family: sans-serif;
  font-size: 20px;
  font-weight: bold;
  width: 600px;
  height: 50px;
  border-radius: 2px;
}
#search:hover {
  background-color: #f0f0f0;
  font-color: #000;
  opacity: 50;
}
img {
  position: absolute;
  top: 10px;
  left: 30px;
}
.mnav {
  position: absolute;
  top: 30px;
  right: 515px;
}
.mnav a {
  font-family: Tahoma;
  font-size: 18px;
  font-weight: bolder;
  color: #000;
  text-decoration: none;
  padding-right: 10px;
  padding-left: 10px;
}
.snav {
  position: absolute;
  top: 50px;
  right: 50px;
}
.snav a {
  padding-right: 5px;
  padding-left: 5px;
}
<!Doctype html>
<html>
<head>
  <title>Two Website</title>
  <link rel="stylesheet" href="two-website.css">
</head>
<body>
  <div class="body_con">
    <div class="header">
    </div>
    <nav class="mnav">
      <a href="#">Home</a>
      <a href="#">Page 1</a>
      <a href="#">Page 2</a>
      <a href="#">Page 3</a>
    </nav>
    <img src="../desktop/logo.png">
    <nav class="snav">
      <a href="https://www.linkedin.com/uas/login">
        <img src="../desktop/linked.png" height="32px" width="32px">
      </a>
      <a href="https://www.facebook.com/">
        <img src="../desktop/fb.png" height="32px" width="32px">
      </a>
      <a href="https://twitter.com/">
        <img src="../desktop/twitter.png" height="32px" width="32px">
      </a>
      <a href="https://plus.google.com/">
        <img src="../desktop/google.png" height="32px" width="32px">
      </a>
    </nav>
    <div class="bar_1">
    </div>
    <div class="bar_2">
    </div>
    <div class="bar_3">
    </div>
    <form action="\" method="get" class="search_bar">
      <input type="text" name="search" placeholder="Search" id="search">
    </form>
  </div>
  <footer id="footer">
  </footer>
</body>
</html>

请帮帮我。

谢谢

2 个答案:

答案 0 :(得分:0)

snav的宽度为:

 5 * (32 + 5 + 5) = 5 * 42 = 210

这样:

.snav {
position: absolute;
top: 50px;
right: 50px;
width: 210px;
height: 32px;
}

P.S。正如在评论中所说,最好考虑相对定位而不是绝对定位。

答案 1 :(得分:0)

snav a 中添加位置:相对并增加填充。

.snav a {
    position: relative;
    padding-right: 15px;
    padding-left: 15px;
}