javascript -
问题描述
我正在制作一个网页,该网页需要在顶部有一个导航菜单,每个部分都有一个标题,使用
<h1>
元素。问题是,当我写标题时,导航消失了。使用
tabTitle {
margin-top: 500px;
}
在 CSS 中只是使页面上的标题更低,并且导航仍然缺失。我怎样才能解决这个问题?
这是代码:
<!doctype html>
<html>
<head>
<meta-charset="utf-8">
<title>Title</title>
</head>
<body>
<div id="top-menubar">
<nav>
<a href=tab1.html">1</a> |
<a href="tab2.html">2</a> |
<a href="tab3.html">3</a> |
<a href="tab4.html">4</a> |
<a href="tab5.html">5</a>
</nav>
<h1 id="tabTitle">Tab 5</h1>
</body>
</html>
<style>
body {
font-family: 'Roboto Condensed', sans-serif;
}
#top-menubar {
font-family: 'Oswald', sans-serif;
float: none;
position: absolute;
left: 50%;
z-index: 1;
transform: translate(-50%, -50%);
text-transform: uppercase;
margin-top: 25px;
color: black;
}
a:link {
text-decoration: none;
color: black;
opacity: 100% !important;
}
a:visited {
text-decoration: none;
color: black;
}
a:hover {
text-decoration: none;
color: black;
transform: scale(2, 3) !important;
border-style: solid;
border-color: #b5b5b5;
background-color: #b5b5b5;
}
a:active {
text-decoration: none;
color: black;
}
#tabTitle {
margin-top: 500px;
}
</style>
回答: 显然,这可以通过应用
position: absolute;
标记到标题。
解决方案
猜猜这可能会对您有所帮助,并且无需将位置定义为绝对
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Roboto Condensed', sans-serif;
}
#top-menubar {
font-family: 'Oswald', sans-serif;
float: none;
/*
position: absolute;
left: 50%;
*/
z-index: 1;
/* transform: translate(-50%, -50%); */
text-transform: uppercase;
/* margin-top: 25px; */
color: black;
/**/
padding: 25px 0 0 0;
background: darkcyan;
width: 100%;
height: 70px;
text-align: center;
}
a:link {
text-decoration: none;
color: black;
opacity: 100% !important;
/* added */
padding: 10px;
margin: 15px;
}
a:visited {
text-decoration: none;
color: black;
}
a:hover {
text-decoration: none;
color: black;
transform: scale(2, 3) !important;
border-style: solid;
border-color: #b5b5b5;
background-color: #b5b5b5;
}
a:active {
text-decoration: none;
color: black;
}
#tabTitle {
/* margin-top: 500px; */
/* added */
margin: 80px 210px;
<body>
<div id="top-menubar">
<nav>
<a href="tab1.html">1</a> |
<a href="tab2.html">2</a> |
<a href="tab3.html">3</a> |
<a href="tab4.html">4</a> |
<a href="tab5.html">5</a>
</nav>
</div>
<h1 id="tabTitle">Tab 5</h1>
</body>
推荐阅读
- eclipse - PyDev 颜色 - 这种颜色叫什么,我该如何改变它?
- reactjs - 如何在 ReactJS 中将 Azure AD B2B 与带有 PKCE 流的授权代码一起使用
- google-sheets - 为什么删除的名称会从链接列表中创建以下错误?
- sql - Django,如何编写 SQL 或 ORM 来总结一些东西?
- html - 如何使用 CSS 动画使图标上下移动
- sql - SQL:如何将 STRING 字段替换/限制为两个可能的值?
- sql-server - MsSql - 几个表上的非聚集索引
- python-3.x - 熊猫滚动窗口获得最小值
- c# - 如何在实体框架数据库第一个模型连接字符串中动态包含工作站 ID?
- docker - 使用 Docker-Compose 文件运行 Docker 容器时的工作目录