Html 所有元素都与导航栏的中心对齐

Html 所有元素都与导航栏的中心对齐,html,css,navbar,center,Html,Css,Navbar,Center,这个导航栏给我带来了很多问题。这次我又面临着一个不同的问题,也许是最困难的 导航栏应位于中心,但不应位于其后的其他元素。你甚至可以看到我之前在这个主题上发布的问题,这些问题与所有元素上溢出的导航栏有关(所有元素都在下面)。解决了那个问题,但又得到了一个新的问题 以下是完整的HTML代码: <!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"

这个导航栏给我带来了很多问题。这次我又面临着一个不同的问题,也许是最困难的

导航栏应位于中心,但不应位于其后的其他元素。你甚至可以看到我之前在这个主题上发布的问题,这些问题与所有元素上溢出的导航栏有关(所有元素都在下面)。解决了那个问题,但又得到了一个新的问题

以下是完整的HTML代码:


<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>Smileybook</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">

<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700,900&display=swap" rel="stylesheet">

<link href="buttonstyle.css" rel="stylesheet">


<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<link rel="stylesheet" href="./style.css">



<style>
div {
  margin-bottom: ;
  padding: ;
}
.info {
 clear: both;
 margin-top: 20px;
 width: 700px;
 background-color: #e7f3fe;
 border-left: 6px solid #2196F3;
 border-radius: 5px;
 transition: opacity 1s;
}
.closebtn {
  margin-left: 5px;
  color: black;
  font-weight: bold;
  float: right;
  font-size: 22px;
  line-height: 30px;
  cursor: pointer;
  transition: 0.5s;
}

.closebtn:hover {
  color: black;
}
</style>

<style>
/* width */
::-webkit-scrollbar {
  width: 10px;
}

/* Track */
::-webkit-scrollbar-track {
  box-shadow: inset 0 0 5px lightblue;
  border-radius: ;
}

/* Handle */
::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: ;
}

/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
  background: #333;
}
</style>


<style>
.buttonhover {
  border-radius: 40px;
  background-image: linear-gradient(90deg , rgb(2, 0, 200) 0%, rgb(9, 9, 121) 0%, rgb(0, 212, 255) 100%);;
  border: solid;
  color: #FFFFFF;
  text-align: center;
  font-size: 13px;
  padding: 14px;
  width: 135px;
  transition: all 0.5s;
  cursor: pointer;
  margin-top: 5px;
  margin-bottom: 5px;
}

.buttonhover span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}

.buttonhover span:after {
  content: '\00bb';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
}

.buttonhover:hover span {
  padding-right: 25px;
}

.buttonhover:hover span:after {
  opacity: 1;
  right: 0;
}
</style>

<style>
/* Full-width input fields */
input[type=text], input[type=password] {
    width: 100%;
    padding: 12px 20px;
    margin: 8px 0;
    border-radius: 20px;
    display: inline-block;
    border: 1px solid #ccc;
    box-sizing: border-box;
}

/* Set a style for all buttons */
button {
    background-color: #2FEA14;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    cursor: pointer;
    width: 100%;
}

button:hover {
    opacity: 0.8;
}

/* Extra styles for the cancel button */
.cancelbtn {
    width: auto;
    padding: 10px 18px;
    background-color: #FFF300;
}

/* Center the image and position the close button */
.imgcontainer {
    text-align: center;
    margin: 24px 0 12px 0;
    position: relative;
}

img.avatar {
    width: 40%;
    border-radius: 50%;
}

.container {
    padding: 16px;
}

span.psw {
    float: right;
    padding-top: 16px;
}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 5; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: manual; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
    padding-top: ;
}

/* Modal Content/Box */
.modal-content {
    background-color: #fefefe;
    margin: 5% auto 15% auto; /* 5% from the top, 15% from the bottom and centered */
    border: 1px solid #888;
    border-radius: 5px ;
    width: 80%; /* Could be more or less, depending on screen size */
}

/* The Close Button (x) */
.close {
    position: absolute;
    right: 30px;
    top: 0;
    color: #000;
    font-size: 35px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: red;
    cursor: pointer;
}

/* Add Zoom Animation */
.animate {
    -webkit-animation: animatezoom 0.6s;
    animation: animatezoom 0.6s
}

@-webkit-keyframes animatezoom {
    from {-webkit-transform: scale(0)}
    to {-webkit-transform: scale(1)}
}

@keyframes animatezoom {
    from {transform: scale(0)}
    to {transform: scale(1)}
}

/* Change styles for span and cancel button on extra small screens */
@media screen and (max-width: 300px) {
    span.psw {
       display: block;
       float: none;
    }
    .cancelbtn {
       width: 100%;
    }
}
</style>

</head>

</div>




<div class"header-container">

<ul id="nav-1">
    <li class="slide1"></li>
    <li class="slide2"></li>
    <li><a href="#">Alpha</a></li>
    <li><a href="#">Beta</a></li>
    <li><a href="#">Gamma</a></li>
    <li><a href="#">Delta</a></li>
    <li><a href="#">Epsilon</a></li>
    <li><a href="#" onclick="document.getElementById('id01').style.display='block'">Login</a></li>
  </ul>











  <div class="info">
     <span class="closebtn">&times;</span>
     <b>Info!</b> You are currently on latest version of Smileybook
     <i>Smileybook 1.2</i>
     Subscribe to Smileybook Notifications and Share you comments on Mail.
   </div>



<div id="id01" class="modal" align="center">


   <form class="modal-content animate" action="https://yashdamani.000webhostapp.com/account/account.html">


<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close ">&times;</span>
</div>



  <div class="container">
  <label><b><i><font color="70bafe">Username</font></i></b>
</label>

     <input type="text" placeholder="Enter Username"name="user" required>




    <label><b><i><font color="70bafe" >Password</font></i></b></label>

   <input type="password" placeholder="Enter Password" name="pass" required>


<a href="https://yashdamani.000webhostapp.com/account/account.html" accesskey="enter">
<button class="btn submit_btn form-control" onclick="document.getElementById('id01').style.display='block'" style="width:20px," type="submit">Login</button></a>

<br>


 <input type="checkbox" checked="checked">
<font color="70bafe" > Remember me
  </font>
</div>



 <div class="container" style="background-color:#f1f1f1">

  <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">
<font color="0A026A"><b>Cancel</b></font></button>


<br>


<a href="https://yashdamani.000webhostapp.com/forgotpassword.html"  accesskey="" ><font color="70bafe" > Forgot Password?</a></font>

<hr color="70bafe">

</div>


</div>

 </form>


</div>





 <script>
 // Get the modal
 var modal = document.getElementById('id01');

 // When the user clicks anywhere outside of the modal, close it
 window.onclick = function(event) {
     if (event.target == modal) {
         modal.style.display = "none";
     }
 }

 </script>



 <script>
 var close = document.getElementsByClassName("closebtn");
 var i;

 for (i = 0; i < close.length; i++) {
   close[i].onclick = function(){
     var div = this.parentElement;
     div.style.opacity = "0";
     setTimeout(function(){ div.style.display = "none"; }, 600);
   }
 }
 </script>

  <script src='./jquery.min.js'></script>
  <script  src="./script.js"></script>


</body>





</html>


请尽早帮助我。

我已经更新了代码


笑脸书
div{
页边距底部:;
填充:;
}
.info{
明确:两者皆有;
边缘顶部:20px;
左边距:10px;
右边距:10px;
宽度:100%;
背景色:#e7f3fe;
左边框:6px实心#2196F3;
边界半径:5px;
过渡:不透明度1s;
}
.关闭{
左边距:5px;
颜色:黑色;
字体大小:粗体;
浮动:对;
字体大小:22px;
线高:30px;
光标:指针;
过渡:0.5s;
}
.closebtn:悬停{
颜色:黑色;
}
/*宽度*/
:-webkit滚动条{
宽度:10px;
}
/*跟踪*/
:-webkit滚动条轨迹{
框阴影:嵌入0 5px浅蓝色;
边界半径:;
}
/*处理*/
:-webkit滚动条拇指{
背景:#ccc;
边界半径:;
}
/*悬停手柄*/
:-webkit滚动条拇指:悬停{
背景:#333;
}
.钮扣{
边界半径:40px;
背景图像:线性梯度(90度,rgb(2,0,200)0%,rgb(9,9,121)0%,rgb(0,212,255)100%);;
边框:实心;
颜色:#FFFFFF;
文本对齐:居中;
字体大小:13px;
填充:14px;
宽度:135px;
过渡:均为0.5s;
光标:指针;
边缘顶部:5px;
边缘底部:5px;
}
.钮扣跨距{
光标:指针;
显示:内联块;
位置:相对位置;
过渡:0.5s;
}
.按钮覆盖范围:之后{
内容:'\00bb';
位置:绝对位置;
不透明度:0;
排名:0;
右:-20px;
过渡:0.5s;
}
.按钮上方:悬停范围{
右边填充:25px;
}
.按钮上方:悬停范围:之后{
不透明度:1;
右:0;
}
/*全宽输入字段*/
输入[类型=文本],输入[类型=密码]{
宽度:100%;
填充:12px 20px;
利润率:8px0;
边界半径:20px;
显示:内联块;
边框:1px实心#ccc;
框大小:边框框;
}
/*为所有按钮设置样式*/
钮扣{
背景色:#2FEA14;
颜色:白色;
填充:14px 20px;
利润率:8px0;
边界:无;
光标:指针;
宽度:100%;
}
按钮:悬停{
不透明度:0.8;
}
/*取消按钮的其他样式*/
.取消{
宽度:自动;
填充:10px 18px;
背景色:#FFF300;
}
/*将图像居中并放置关闭按钮*/
.imgcontainer{
文本对齐:居中;
保证金:24px 0 12px 0;
位置:相对位置;
}
化身{
宽度:40%;
边界半径:50%;
}
.集装箱{
填充:16px;
}
span.psw{
浮动:对;
填充顶部:16px;
}
/*模态(背景)*/
.莫代尔{
显示:无;/*默认情况下隐藏*/
位置:固定;/*保持原位*/
z指数:5;/*位于顶部*/
左:0;
排名:0;
宽度:100%;/*全宽*/
高度:100%;/*全高*/
溢出:手动;/*根据需要启用滚动*/
背景色:rgb(0,0,0);/*回退色*/
背景色:rgba(0,0,0,0.4);/*黑色w/不透明度*/
填充顶部:;
}
/*模态内容/框*/
.模态内容{
背景色:#fefe;
保证金:5%自动15%自动;/*5%从顶部,15%从底部和居中*/
边框:1px实心#888;
边界半径:5px;
宽度:80%;/*可能更多或更少,具体取决于屏幕大小*/
}
/*关闭按钮(x)*/
.结束{
位置:绝对位置;
右:30px;
排名:0;
颜色:#000;
字体大小:35px;
字体大小:粗体;
}
.关闭:悬停,
.结束:聚焦{
颜色:红色;
光标:指针;
}
/*添加缩放动画*/
.制作动画{
-webkit动画:animatezoom 0.6s;
动画:动画空间0.6s
}
@-webkit关键帧动画库{
来自{-webkit变换:缩放(0)}
到{-webkit转换:缩放(1)}
}
@关键帧动画空间{
来自{transform:scale(0)}
到{变换:比例(1)}
}
/*更改超小屏幕上“跨度”和“取消”按钮的样式*/
@媒体屏幕和屏幕(最大宽度:300px){
span.psw{
显示:块;
浮动:无;
}
.取消{
宽度:100%;
}
}
.收割台容器{
显示器:flex;
宽度:100%;
最大宽度:100%;
边缘顶部:10px;
柔性包装:包装;
}
.导航控制
{
文本对齐:居中;
宽度:100%;
}
#导航-1{
位置:相对位置;
宽度:最大含量;
边界:无;
边缘顶部:10px;
浮动:无;
边界半径:20em;
显示:内联块;
//显示:-网络工具包盒;
//显示:-ms flexbox;
显示:内联flex;
列表样式:无;
背景:#f5;
盒影:20px 40px 40px 00000033;
填充:10px;
}
#导航1里{
边际:0px;
}
#导航-1李娜{
位置:相对位置;
填料:0.6em2em;
字号:18px;
边界:无;
大纲:无;
颜色:#333;
显示:内联块;
文字装饰:无;
z指数:3;
}
#导航-1.幻灯片1,
#导航-1.幻灯片2{
位置:绝对位置;
显示:内联块;
高度:3em;
边界半径:10em;
-webkit过渡:所有0.6s立方贝塞尔(0.23,1,0.32,1.05);
过渡:所有0.6s三次贝塞尔(0.23,1,0.32,1.05);
}
#导航-1.幻灯片1{
背景颜色:浅蓝色;
z指数:2;
}
#导航-1.幻灯片2{
不透明度:0;
背景:ddd;
z指数:1;
}
#nav-1.挤压{
-webkit变换:比例(0.9);
变换:比例(0.9);
}
*,
*::之前,
*::之后{
框大小:边框框;
}
身体{
显示:-网络工具包盒;
显示器:flex;
-webkit盒包:中心;
//证明内容:中心;
-webkit框对齐:居中;
对齐项目:居中;
背景色:#E0;
字体系列:蒙特塞拉特,无衬线;
线高:1.5;
背景:白色;
}
  • <
    
    .header-container {
      display: flex;
      max-width: 100%;
      margin-top: 10px;
      flex-wrap: wrap;
    }
    
    #nav-1 {
      position: relative;
      border: none;
      margin-top: 10px;
      float: none;
      border-radius: 20em;
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      list-style: none;
      background: #f5f5f5;
      box-shadow: 20px 40px 40px #00000033;
      padding: 10px;
    }
    
    #nav-1 li {
      margin: 0px;
    }
    
    #nav-1 li a {
      position: relative;
      padding: 0.6em 2em;
      font-size: 18px;
      border: none;
      outline: none;
      color: #333;
      display: inline-block;
      text-decoration: none;
      z-index: 3;
    }
    
    #nav-1 .slide1,
    #nav-1 .slide2 {
      position: absolute;
      display: inline-block;
      height: 3em;
      border-radius: 10em;
      -webkit-transition: all 0.6s cubic-bezier(0.23, 1, 0.32, 1.05);
      transition: all 0.6s cubic-bezier(0.23, 1, 0.32, 1.05);
    }
    
    #nav-1 .slide1 {
      background-color: lightblue;
      z-index: 2;
    }
    
    #nav-1 .slide2 {
      opacity: 0;
      background: #ddd;
      z-index: 1;
    }
    
    #nav-1 .squeeze {
      -webkit-transform: scale(0.9);
      transform: scale(0.9);
    }
    
    *,
    *::before,
    *::after {
      box-sizing: border-box;
    }
    
    body {
      display: -webkit-box;
      display: flex;
      -webkit-box-pack: center;
              justify-content: center;
      -webkit-box-align: center;
              align-items: center;
      background-color: #e0e0e0;
      font-family: Montserrat, sans-serif;
      line-height: 1.5;
      background: white;
    }