我开始编写一个网站代码,在那里我开始使用CSS编写HTML代码。但是,我认为我犯了一个错误,即在我开始编程之前我没有放<div>
。
以下是导航栏的代码:
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
li {
float: left;
border-right: 0px solid #bbb;
}
li:last-child {
border-right: none;
}
li a {
display: block;
color: white;
text-align: center;
padding: 19px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #112;
}
.active {
background-color: #990000;
}
body {
margin: 0;
}
ul.topnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
background-color: #333;
-webkit-transition: all 0.4s ease;
-moz-transition: all 0.4s ease;
transition: all 0.4s ease;
}
ul.topnav li {
float: left;
}
ul.topnav li a {
display: inline-block;
color: #FFF;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 17px;
font-family: 'Dosis', sans-serif;
}
ul.topnav li a:hover {
background-color: #990000;
}
ul.topnav li active {
background-color: #990000;
}
ul.topnav li.icon {
display: none;
}
@media screen and (max-width: 680px) {
ul.topnav li:not(:first-child) {
display: none;
}
ul.topnav li.icon {
float: right;
display: inline-block;
}
}
@media screen and (max-width: 680px) {
ul.topnav.responsive {
position: fixed;
}
ul.topnav.responsive li.icon {
position: absolute;
right: 0;
top: 0;
}
ul.topnav.responsive li {
float: none;
display: inline;
}
ul.topnav.responsive li a {
display: block;
text-align: left;
}
function myFunction() {
var x=document.getElementById("myTopnav");
if (x.className==="topnav") {
x.className +=" responsive";
}
else {
x.className="topnav";
}
}
}
.videoWrapperOuter {
max-width: 640px;
margin-left: auto;
margin-right: auto;
}
.videoWrapperInner {
float: none;
clear: both;
width: 100%;
position: relative;
padding-bottom: 50%;
padding-top: 25px;
height: 0;
}
.videoWrapperInner iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.container {
width: 100%;
max-width: 40.7em;
margin: 0 auto;
}
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<ul class="topnav" id="myTopnav">
<li class="active">
<a href="index.html">
<i class="fa fa-home" aria-hidden="true"></i>
</a>
</li>
<li><a href="contact.html">Contact</a>
</li>
<li><a href="studio.html">Rent a Studio</a>
</li>
<li class="icon">
<a href="javascript:void(0);" style="font-size:15px;" onclick="myFunction()">
<i class="fa fa-bars" aria-hidden="true"></i>
</a>
</li>
</ul>
我想在右边放一个文字横幅,当我崩溃时,文字横幅就在导航栏的中间。
答案 0 :(得分:0)
在列表中添加了以下li
以及right
和mob
类。
<li class="right mob"><a href="#">Heading</a>
</li>
请告诉我这是否符合您的预期?谢谢!
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
li {
float: left;
border-right: 0px solid #bbb;
}
li:last-child {
border-right: none;
}
li a {
display: block;
color: white;
text-align: center;
padding: 19px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #112;
}
.active {
background-color: #990000;
}
body {
margin: 0;
}
ul.topnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
background-color: #333;
-webkit-transition: all 0.4s ease;
-moz-transition: all 0.4s ease;
transition: all 0.4s ease;
}
ul.topnav li {
float: left;
}
ul.topnav li.right{
float: right;
}
ul.topnav li a {
display: inline-block;
color: #FFF;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 17px;
font-family: 'Dosis', sans-serif;
}
ul.topnav li a:hover {
background-color: #990000;
}
ul.topnav li active {
background-color: #990000;
}
ul.topnav li.icon {
display: none;
}
@media screen and (max-width: 680px) {
ul.topnav li:not(.mob) {
display: none;
}
ul.topnav li.icon {
float: right;
display: inline-block;
}
ul.topnav li.right{
float: none;
text-align: center;
}
}
@media screen and (max-width: 680px) {
ul.topnav.responsive {
position: fixed;
}
ul.topnav.responsive li.icon {
position: absolute;
right: 0;
top: 0;
}
ul.topnav.responsive li {
float: none;
display: inline;
}
ul.topnav.responsive li a {
display: block;
text-align: left;
}
ul.topnav.responsive li.right{
position: absolute;
top:0;
left: 50%;
transform: translate(-50%, 0);
}
}
.videoWrapperOuter {
max-width: 640px;
margin-left: auto;
margin-right: auto;
}
.videoWrapperInner {
float: none;
clear: both;
width: 100%;
position: relative;
padding-bottom: 50%;
padding-top: 25px;
height: 0;
}
.videoWrapperInner iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.container {
width: 100%;
max-width: 40.7em;
margin: 0 auto;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<ul class="topnav" id="myTopnav">
<li class="active mob">
<a href="index.html">
<i class="fa fa-home" aria-hidden="true"></i>
</a>
</li>
<li><a href="contact.html">Contact</a>
</li>
<li><a href="studio.html">Rent a Studio</a>
</li>
<li class="icon">
<a href="javascript:void(0);" style="font-size:15px;" onclick="myFunction()">
<i class="fa fa-bars" aria-hidden="true"></i>
</a>
</li>
<li class="right mob"><a href="#">Heading</a>
</li>
</ul>