html - 如何使我的导航栏响应移动设备(包括 Codepen)?

标签 html css

我目前正在使我的网页响应。我在导航栏上苦苦挣扎,不知道从哪里开始让它适合移动设备。这是我的导航栏的样子:

HTML:

<head>

  <link href="https://fonts.googleapis.com/css?family=Gilda+Display|Montez|Sacramento" rel="stylesheet">

</head>


<nav>
      <div class="navcontainer">
         <ul>
            <li class="right"><a href="productPage.php">Shop</a></li>
            <li class="right"><a href="">Login</a></li>
            <li><a href="index.php"><img class="logo" src="http://rubyfearless.com/wp-content/uploads/2012/08/style-insider-logo221.jpeg"></a></li>
            <li class="right"><a href="contact.php">Contact us</a></li>
            <li class="right"><a href="blog/cms.php">Blog</a></li>
         </ul>
      </div>
     </nav>

     <div class="clearfix"></div>

CSS:

html, body {
  margin: auto;
  padding: 0px;
}

.container{
    margin: 0 auto;
    width: 85%;
}

.clearfix{
    clear:both;
}


/*******************************/

/*********************HEADER*******************/



nav {
  text-align: center;
  width: 100%;
  background-color: white;
  border:2px solid black;
}

nav ul {
  padding: 0;
  margin:0;
}

nav li {
  color: black;
  display: inline-block;
  font-size: 30px;
  font-weight: 300;
  font-family: 'Sacramento', cursive;
  vertical-align: middle;
  margin: 16px 20px;
}



li a{
    text-decoration: none;
    color: black;
}

.logo{
    height:100px;
}

这是我的导航栏的codepen代码:

https://codepen.io/teenicarus/pen/vZWJxX

这是我希望它在移动设备上的样子:

enter image description here

我该从哪里开始创建类似的结果?

感谢所有回复。

最佳答案

您需要使用@media 查询来根据屏幕尺寸覆盖 css...工作示例如下

html, body {
  margin: auto;
  padding: 0px;
}

.container{
	margin: 0 auto;
	width: 85%;
}

.clearfix{
	clear:both;
}


/*******************************/

/*********************HEADER*******************/



nav {
  text-align: center;
  width: 100%;
  background-color: white;
  border:2px solid black;
}

nav ul {
  padding: 0;
  margin:0;
}

nav li {
  color: black;
  display: inline-block;
  font-size: 30px;
  font-weight: 300;
  font-family: 'Sacramento', cursive;
  vertical-align: middle;
  margin: 16px 20px;
}



li a{
	text-decoration: none;
	color: black;
}

.logo{
	height:100px;
}
.small-screen{display:none;}
@media screen and (max-width: 768px) {
  nav li {display:block}
  .small-screen{display:block;}
   .large-screen{display:none;}
}
<head>
  
  <link href="https://fonts.googleapis.com/css?family=Gilda+Display|Montez|Sacramento" rel="stylesheet">
  
</head>


<nav>
	  <div class="navcontainer">
		 <ul>
       <li class="small-screen"><a href="index.php"><img class="logo" src="http://rubyfearless.com/wp-content/uploads/2012/08/style-insider-logo221.jpeg"></a></li>
		 	<li class="right"><a href="productPage.php">Shop</a></li>
		 	<li class="right"><a href="">Login</a></li>
		    <li class="large-screen"><a href="index.php"><img class="logo" src="http://rubyfearless.com/wp-content/uploads/2012/08/style-insider-logo221.jpeg"></a></li>
		 	<li class="right"><a href="contact.php">Contact us</a></li>
		 	<li class="right"><a href="blog/cms.php">Blog</a></li>
		 </ul>
	  </div>
	 </nav>

	 <div class="clearfix"></div>

关于html - 如何使我的导航栏响应移动设备(包括 Codepen)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44778402/

相关文章:

php/mysql 表单验证问题

html - 悬停后颜色 TD

javascript - 为什么我收到 "Fatal error: Call to a member function query() on a non-object"错误?

javascript - 停止额外间隔

css - 具有三个背景图像并居中于同一位置的 Flexbox?

javascript - 垂直内联的 Div 框

javascript - 链接和按钮未对齐

html - 从超链接图像中删除下划线

jQuery 不适用于多个 div 类

html - IE 中的 float 未正确对齐