如何修复导航栏以使其居中并使其在两侧均匀?

时间:2019-03-07 21:18:18

标签: html css

一旦我将窗口缩小到500px以下,就会出现问题;我创建了一个媒体查询来根据显示的大小更改大小。不幸的是,这样做时,所有菜单项似乎都向左浮动,并且有太多的空白空间,使事情变得不平衡。我尝试了各种居中方法,但无法确定问题所在。与往常一样,我们非常感谢您的帮助。这是我的HTML CSS工作文件:

* {
    padding:0;
    margin: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    
}


.wrapper {
    min-height: 100%;
    min-width: 100%;
    display: inline-block;
    position: relative;    
}

body{
    height: 100%;
    background-size: cover; 
    background-repeat: no-repeat; background:url("https://images.pexels.com/photos/1054198/pexels-photo-1054198.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
}

.imagebox {
    margin:0px auto;
   width:800px;
}

.banner {
    font-size: 18px;
    background:rgba(0, 33,33, .3);
    color:aliceblue;
    
}

h2{
    padding:10px;
    background: #646ecb;
    min-width: 500px;
    color:#f0f1f5;
    font-size: 30pt;
    text-align: center;
}

.Logo {
         text-align: center;
         height: 130px;
         width: 260px;
     }

hr.style-one {
    border: none;
    height: 1px;
    min-width: 500px;
    margin:20px auto;
    background: #333;
    background-image: linear-gradient(to right, #646ecb, #fff, #646ecb);
}

.navbar {
    background: teal;
    height: 40px;
    width:700px;
    display: block;
    margin:0 auto;
    text-align: center;
    font-size: 14px;
     font-weight: bold;
    border-bottom: 4px solid aliceblue;
}


nav ul {
    list-style: none;
    display: block;
    color:aliceblue;
    font-family:arial;
    font-size:18px;
}

nav a {
    display: inline-block;
    text-decoration:none;
    font-weight: bold;
    font-size: 20px;
    color: aliceblue;
    
    
}

nav a:hover {
    color: #a2f3fe;
;
}


nav ul li:hover ul li {
    display:block;
    background: teal;
}


nav ul li {
    float:left;
    width:140px;
    height: 40px;
    line-height: 40px;
}

nav ul ul li{
    position: relative;
    display:none;
}

h3{
    text-align: center;
    font-family:"Pathway Gothic One";
    color:aliceblue;
    margin:10 auto;
    text-shadow: 1px 2px rgba(0,0,0,.1);
    padding: 5px;
    min-width: 700px;
    font-size: 20pt;
    letter-spacing: 2px;
}



article{
    margin:20px 20px;
    text-align: center;
}

 fieldset
{
    height: 20%;
    width: 70%;
    background: rgba(0,0,0,.4);
    text-align:center;
    margin:auto;
    color:;
}

 @media (max-width: 500px) {
      body {
        background:url("https://c.pxhere.com/photos/07/83/adult_background_beach_black_sand_brunette_clear_sky_coast_coastline-1527307.jpg!d");
        background-size: cover;
          background-repeat: no-repeat;
        height:100%;
      }
     

     
--------------------------------------------------------------------------------------------------------------------------------------------------------------*/
     
     
     h2{
    padding: 20px;
    background: #646ecb;
    font-size: 30px;
    text-align: center;
    
}
     
     .Logo {
         text-align: center;
         height: 60px;
         width: 120px;
     }

     
 
 fieldset
{
    height: 25%;
    width: 70%;
    background: rgba(0,0,0,.4);
    text-align:center;
    margin:auto;
    color:red;
}
     
     .imagebox {
         width: 700px;
         margin:0 auto;
         text-align: center;
}

     
     h3 {
         font-size:14px;
         font-family:"pathway gothic one";
         line-height:10px;
}
     
     
     hr.style-one {
    border: none;
    height: 1px;
    min-width: 400px;
    background-image: linear-gradient(to right, #646ecb, #fff, #646ecb);
         margin:4px auto;
}
     
     .navbar {
    background: teal;
    height: 30px;
    width:400px;
    display: block;
    font-size: 12px;
    font-weight: bold;
    border-bottom: 4px solid darkorchid;
     }


nav ul {
    list-style: none;
    display: block;
    color:aliceblue;
    font-size:12px;
}

nav a {
    display: inline-block;
    text-decoration:none;
    font-weight: bold;
    font-size: 12px;
    color: aliceblue;
    margin:0px;
    
    
}

nav a:hover {
    color: #a2f3fe;
;
}


nav ul li:hover ul li {
    display:block;
    background: teal;
    
}


nav ul li {
    float:center;
    width:70px;
    height: 30px;
    line-height: 30px;
}

nav ul ul li{
    position: relative;
    display:none;
    
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS -->

    
  <link rel="stylesheet" type="text/css" href="css/maintravel.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
  <link href="https://fonts.googleapis.com/css?family=Pathway+Gothic+One" rel="stylesheet">



  <title>Round-a-Whirl</title>
</head>

<body>
  <div class="wrapper">
    <header>
      <div></div>
      <h2><img src="HatchfulExport-All/linkedin_banner_image_1.png" height=75 width="auto" class="Logo"></h2>
    </header>
    <div class="navbar">
      <nav>
        <ul>
          <li><a href="#"><i class="fa fa-plane"> </i> Flights</a></li>
          <li><a href="#"><i class="fa fa-hotel"> </i> Hotel</a></li>
          <li><a href="#"><i class="fa fa-car"> </i>  Rental</a></li>
          <li><a href="#"><i class="fa fa-globe"> </i> Discover</a>
            <ul>
              <li> Vacation</li>
              <li> Cruise</li>
              <li> City</li>
              <li> Nature</li>
              <li> Getaways</li>
            </ul>
          </li>
          <li><a href="#"><i class="fa fa-tag"></i> Deals</a> </li>
        </ul>
      </nav>
    </div>
      <hr class="style-one" width="20%">
      <h3>Don't travel in Whirl! Find flights and compare</h3>
      <hr class="style-one" width="20%">
      
      
          
<head>

<style>
div.gallery {
  margin: 5px;
  border: 1px solid #ccc;
  float: left;
  width: 180px;
}

div.gallery:hover {
  border: 1px solid #777;
}

div.gallery img {
  width: 100%;
  height: auto;
}

div.desc {
  padding: 15px;
  text-align: center;
}
</style>
</head>
<body>
<article>
    This is a simple site I created using HTML and CSS of a travel site for the fictional Round-a-Whirl travel company. 
    <br /><br />
    <p class="banner">Check out our all inclusive vacation packages!</p>
  </article>
    
    <fieldset>
    <form>
        
Origin:<input type="text" name="Origin">  
        Destination:<input type="text"><br /><br />
      
Depart:<input type="date">
Return:<input type="date">
        
        </form></fieldset>
    

  <!-- Optional JavaScript -->
  <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

</html>

1 个答案:

答案 0 :(得分:0)

     @media (max-width: 500px)
nav ul li {
    float: left;
    width: 103px;
    height: 30px;
    line-height: 30px;
    text-align: center;
}

.navbar {
    width: 100%;
}
hope this will help you