我想在导航菜单上方显示社交媒体图标。但是现在总是来不及将菜单停留在页面顶部。如何在topnav上方提供空间,以便可以将社交图标代码放在页面顶部。所有时间菜单都位于页面上方,社交栏或任何文本现在都显示在菜单顶部上方。我想在菜单顶部显示一些图标和文字。
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.topnav {
overflow: hidden;
background-color: #333;
padding-left: 50px;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 15px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav .icon {
display: none;
}
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
<div class="topnav" id="myTopnav">
<a class="active" href="../index.php">Home <span class="sr-only">(current)</span></a>
<a title="Pregnancy" href="../c-pregnancy">Pregnancy</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>
答案 0 :(得分:0)
以下是您的意思吗?如果不是这样,您需要通过提供所需示例(图片)来澄清您的问题。
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.social {
background: red;
padding: 5px 50px;
}
.topnav {
overflow: hidden;
background-color: #333;
padding-left: 50px;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 15px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav .icon {
display: none;
}
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="social">
<a href="#"><i class="material-icons">android</i></a>
</div>
<div class="topnav" id="myTopnav">
<a class="active" href="../index.php">Home <span class="sr-only">(current)</span></a>
<a title="Pregnancy" href="../c-pregnancy">Pregnancy</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>