简体   繁体   English

使导航菜单响应

[英]Making navigation menu responsive

This is the first time I am doing any css after college. 这是我大学毕业后第一次做CSS。 I have managed to write this pen : 我设法写了这支笔:

Navigation with hover effect 悬停导航

But If you resize the browser, everything gets messed up. 但是,如果您调整浏览器的大小,一切都会变得混乱。 So far I have just used bootstrap to make website prototypes. 到目前为止,我只是使用引导程序制作网站原型。 But now I am trying to learn some design myself. 但是现在我想自己学习一些设计。

How should I go ahead solving problems like this . 我应该如何继续解决这样的问题。

Here is the code : pen 这是代码: pen

The typical best practice here would be to know your toolbox. 这里的典型最佳实践是了解您的工具箱。 You are not forced to utilize all of bootstrap by including it. 您不必通过包括它就可以利用所有引导程序。 However, you can reasonably simply override the default stylings by simply making a styles.css and just using navbar or navbar-fixed or whatever class you want, and then putting your own CSS in styles.css and you get the best of both words. 但是,您可以通过简单地制作styles.css并仅使用navbar或navbar-fixed或所需的任何类,然后将自己的CSS放入styles.css中,从而合理地覆盖默认样式,这两个词都可以发挥最大的作用。

You should do some researches about media queries , which will allow you to adapt your styles for every screen sizes. 您应该对媒体查询进行一些研究,这将使您可以针对每种屏幕尺寸调整样式。 After that, you will be able to set different paddings or margins (for example) when the screen is resized. 之后,您可以在调整屏幕大小时设置不同的填充或边距(例如)。

To fix the problem where it breaks, you need to add this to your class 为了解决问题,您需要将其添加到班级中

.bmenu li {
    border-right: 1px solid rgba(20, 0, 0, 0.4);
    clear: both;
    display: inline-block;//This will stop your nav from overflowing over eachother
    font-size: 20px;
    font-weight: bold;
    height: 20px;
    padding: 20px;
}

I would still use media queries and just adjust for each size. 我仍然会使用媒体查询,只是调整每个大小。 You may at some point need to stack. 您可能在某个时候需要堆叠。 Go to CSS-tricks.com and see how Chris does his nav when you resize the browser. 转到CSS-tricks.com,查看Chris在调整浏览器大小时的导航方式。 Hope this helps. 希望这可以帮助。

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

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