简体   繁体   English

如何使“当前CSS”下拉菜单变得自适应和移动友好?

[英]How do I make my Current CSS Drop down menu Responsive and mobile friendly?

I am having trouble with this, I have looked through other peoples questions and answers I have found some helpful info however I am struggling to apply it to my menu. 我遇到了麻烦,已经浏览了其他人的问题和答案,发现了一些有用的信息,但是我正在努力将其应用于菜单。 I am looking for my current menu which is pure CSS and HTML no other scripts or code to become fully responsive and mobile friendly. 我正在寻找我当前的菜单,该菜单是纯CSS和HTML,没有其他脚本或代码能够完全响应并移动友好。 ie I want to make sure when the browser window size is reduced that the menu also gets smaller then to the point where it turns into the mobile button that you tap to expand. 即,我想确保在减小浏览器窗口大小时,菜单也会变小,然后变成可以点击以展开的移动按钮。

I am hoping someone can show me the exact code I need to add to it with the correct class names etc. I have already tried and failed at this by trying to adapt other peoples answers. 我希望有人可以向我展示我需要添加的正确代码,以及正确的类名等。我已经尝试通过调整其他人的答案来解决这一问题。 I am aware there are various places that will "build" one for free and give me the code however I want the desktop version of my menu to be 100% the same I just need it to scale properly to smaller screens. 我知道有很多地方可以免费“构建”一个地方并提供代码,但是我希望菜单的桌面版本是100%相同,我只需要将其正确缩放到较小的屏幕即可。

I also do not want to use jquery javascript or anything else that is not HTML5 or CSS3, the code is inserted into my index.php and css into my external css file, 我也不想使用jquery javascript或其他非HTML5或CSS3的代码,将代码插入到我的index.php中,将CSS插入我的外部CSS文件中,

From my index page: 从我的索引页面:

     <!-- NAV-BAR-START --> 

  <div id="navbar"><div id='cssmenu'>
     <ul>
       <li><a href='/?p=home'><span>Home</span></a></li>
   <li class='has-sub'><a href='/?p=gallery'><span>Gallery</span></a>
  <ul>
     <li><a href='/?p=photos'><span>Photos</span></a></li>
     <li><a href='/?p=videos'><span>Videos</span></a></li>
     <li><a href='/?p=audio'><span>Audio</span></a></li>
   </ul>
 </li>
 <li class='has-sub'><a href='/?p=ian-milne'><span>Ian Milne</span></a>
  <ul>
      <li><a href='/?p=about'><span>About Ian</span></a></li>
      <li><a href='/?p=testimonials'><span>Testimonials</span></a></li>
     <li class='last'><a href='/?p=location'><span>Location</span></a></li>
   </ul>
 </li>
  <li><a href='/?p=events'><span>Events</span></a></li>
   <li><a href='/?p=bookings'><span>Bookings</span></a></li>
<li class='last'><a href='/?p=contact'><span>Contact</span></a></li>
< /ul> 
 </div></div>

  <!-- NAV-BAR-END -->

And the associated CSS: 以及相关的CSS:

/* CSS DROPDOWN MENU */

#cssmenu {
  border: none;
  border: 0px;
  margin: 0px;
  padding: 0px;
  font: 67.5% 'Lucida Sans Unicode', 'Bitstream Vera Sans', 'Trebuchet Unicode MS', 'Lucida Grande', Verdana, Helvetica, sans-serif;
  font-size: 14px;
  font-weight: bold;
  width: auto;
  text-align:center;

}
#cssmenu ul {
  background: #000dfa;
  height: 50px;
  list-style: none;
  margin: 0;
  padding: 0;
  -webkit-border-radius: 8px 8px 0px 0px;
  -moz-border-radius: 8px 8px 0px 0px;
  border-radius: 8px 8px 0px 0px;
  -webkit-box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
  -moz-box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
  box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
}
#cssmenu li {
  float: none;
  padding: 0px 0px 0px 15px;
  display: inline-block;
}
#cssmenu li a {
  color: #ffffff;
  display: block;
  font-weight: normal;
  line-height: 50px;
  margin: 0px;
  padding: 0px 25px;
  text-align: center;
  text-decoration: none;
}
#cssmenu li a:hover {
  background: #000894;
  color: #ff8400;
  text-decoration: none;
  -webkit-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
  box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
}
#cssmenu ul li:hover a {
  background: #000894;
  color: #ff8400;
  text-decoration: none;
}
#cssmenu li ul {
  display: none;
  height: auto;
  padding: 0px;
  margin: 0px;
  border: 0px;
  position: absolute;
  width: 200px;
  z-index: 200;
}
#cssmenu li:hover ul {
  display: block;
}
#cssmenu li li {
  display: block;
  float: none;
  margin: 0px;
  padding: 0px;
  width: 200px;
  background: #000dfa;
  /*this is where the rounded corners for the dropdown disappears*/

}
#cssmenu li:hover li a {
  background: none;
}
#cssmenu li ul a {
  display: block;
  height: 50px;
  font-size: 12px;
  font-style: normal;
  margin: 0px;
  padding: 0px 10px 0px 15px;
  text-align: left;
}
#cssmenu li ul a:hover,
#cssmenu li ul li:hover a {
  border: 0px;
  color: #ff8400;
  text-decoration: none;
  background: #000894;
  -webkit-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
  box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
}

I have now put this into jsfiddle aswell for those who were asking 我现在也将这些内容放入jsfiddle中,以供那些要求

http://jsfiddle.net/GregTimeassistant/WLP8h/ http://jsfiddle.net/GregTimeassistant/WLP8h/

You can style for each media query. 您可以为每个媒体查询设置样式。 Just copy/paste all your styles for each case. 只需复制/粘贴每种情况下的所有样式。 You can resize your browser window so you can see the result for each media query. 您可以调整浏览器窗口的大小,以便查看每个媒体查询的结果。 Just experiment a lot, you will see that it is easy to customize your design for each aspect ratio. 只需进行大量实验,您就会发现很容易针对每个纵横比自定义设计。

@media (max-width: 600px) {
 #cssmenu {
  /*
  copy styles here
  */
 }
}

Check this example that covers a lot of devices (but needs some updating for new HD smartphones and tablets). 检查涵盖许多设备的此示例(但需要对新的高清智能手机和平板电脑进行一些更新)。 https://gist.github.com/marcobarbosa/798569 https://gist.github.com/marcobarbosa/798569

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM