html - 我需要 &NBSP 实体在 li 标签之间留出空间,但是当应用悬停状态的下划线时,它会延伸到空间所在的位置

标签 html css

首先是 html 和 css

HTML:

<!DOCTYPE html>
<!-- Language And Resource Imports -->
<html lang="en">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Doppio+One|Rajdhani|Quicksand|Raleway&effect=shadow-mutliple|outline">
<link rel="stylesheet" href="resources/css/style.css">
<script src="resources/js/script.js"></script>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>JF Web | Page 1</title>
</head>

<header>
  <div id="titlebar">
    <div id="logotext">
      <h1>JF Web &copy;</h1>
    </div>
    <nav>
      <ul id="navbar" class="cf">
        <li><a href="Index.html" class="active">&nbsp;&nbsp;Page 1&nbsp;&nbsp;</a></li>
        <li><a href="">&nbsp;&nbsp;Page 2&nbsp;&nbsp;</a></li>
        <li><a href="">&nbsp;&nbsp;Page 3&nbsp;&nbsp;</a></li>
      </ul>
    </nav>
  </div>
</header>
<body onload="mainClock()">
<span id="clock"></span>


</body>
</html>

CSS:

#logotext {
  font-family: 'Doppio one';
  font-size: 25px;
  margin-left: 20px;
  float: left;
  width: 45%;
  position: relative;
  top: 25.5px;
}

.cf {
  clear: both;
}

#navbar {
    list-style-type: none;
    float: right;

}

#navbar a {
  text-decoration: none;
  color: white;

}

#navbar a:hover {
  color: rgb(204, 153, 0);
  text-decoration: underline;

}

#navbar li {
  display: inline;
}

#clock {
  font-family: Rajdhani;
  font-size: 30px;
  position: absolute;
  top: 0;
  right: 0;
  margin-top: 5px;
  margin-right: 10px;
}



#titlebar {
  width: 80%;
  margin: 0;
  padding: 0;
  background-color: #414a4c;
  overflow: hidden;
}

所以你可以看到导航栏使用内联无序列表,所以为了在 anchor 文本之间放置一个空格,我在 anchor 文本的两侧使用了两个 nbsp 实体,但是当悬停状态处于事件状态并应用下划线时它也强调了 nbsp NBSP Underline

如果有任何帮助,我们将不胜感激

最佳答案

您可以删除 &nbsp; , 并替换为 CSS padding<a> 上标签:

#navbar a {
  padding: 0 .5em;
}

#logotext {
  font-family: 'Doppio one';
  font-size: 25px;
  margin-left: 20px;
  float: left;
  width: 45%;
  position: relative;
  top: 25.5px;
}

.cf {
  clear: both;
}

#navbar {
    list-style-type: none;
    float: right;

}

#navbar a {
  text-decoration: none;
  color: white;
  padding: 0 .5em; /* Padding can replace spaces*/

}

#navbar a:hover {
  color: rgb(204, 153, 0);
  text-decoration: underline;

}

#navbar li {
  display: inline;
}

#clock {
  font-family: Rajdhani;
  font-size: 30px;
  position: absolute;
  top: 0;
  right: 0;
  margin-top: 5px;
  margin-right: 10px;
}



#titlebar {
  width: 80%;
  margin: 0;
  padding: 0;
  background-color: #414a4c;
  overflow: hidden;
}
<!DOCTYPE html>
<!-- Language And Resource Imports -->
<html lang="en">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Doppio+One|Rajdhani|Quicksand|Raleway&effect=shadow-mutliple|outline">
<link rel="stylesheet" href="resources/css/style.css">
<script src="resources/js/script.js"></script>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>JF Web | Page 1</title>
</head>

<header>
  <div id="titlebar">
    <div id="logotext">
      <h1>JF Web &copy;</h1>
    </div>
    <nav>
      <ul id="navbar" class="cf">
        <li><a href="Index.html" class="active">Page 1</a></li>
        <li><a href="">Page 2</a></li>
        <li><a href="">Page 3</a></li>
      </ul>
    </nav>
  </div>
</header>
<body onload="mainClock()">
<span id="clock"></span>


</body>
</html>

关于html - 我需要 &NBSP 实体在 li 标签之间留出空间,但是当应用悬停状态的下划线时,它会延伸到空间所在的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51178777/

相关文章:

Android kitkat webview css 定位

html - 如何在div中居中放置一组元素

php - 在网页上创建动态网格系统

css - 使用 CSS 类设置元素样式

javascript - jQuery:如何让点击左侧菜单以外的任何地方关闭所述窗口?

javascript - 使用 Javascript 将 CSS 样式表作为字符串注入(inject)

html - 缩放图像并将它们 float 成一行

html - 固定横幅中的图片

jquery - animate 中的 if 语句

php - 尝试创建第二个 loop-single.php 以显示不同的帖子