jquery - 如果在导航栏的 CSS 中

标签 jquery css

当div中的内联元素在多行时,我需要删除一行代码,但我不知道该怎么做

本页

<style>
body {
    background-color: black;
}
#nav {
    color: #fff;
    border: 4px solid white;
    background: #000;
    text-align: center;
}
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
li {
    /*if goes on multiple rows, remove 'display:inline-block'*/
    display: inline-block;
}
li a {
    color: white;
    display: block;
    padding: 2.5px 6px;
}
li a:hover {
    color: black;
    background-color: white;
}
#active {
    text-decoration: none;
    background-color: white;
    color: black;
    pointer-events: none;
    cursor: default;
}
</style>
<nav id="nav">
<ul>
<li><a href="i" id="active">Home</a></li><li><a href="">Page1</a></li><li><a href="">Wow</a></li><li><a href="">Asdfgh</a></li><li><a href="">Test</a></li><li><a href="">CSS</a></li>
</ul>
</nav>

调整大小时,应该是这样的: enter image description here

我该怎么做? 提前致谢

最佳答案

你应该使用 media query .

这将允许您针对特定的屏幕宽度范围使用特定的 CSS 规则。

因此,在确定宽度后,您希望 li 项以这种方式显示,只需编写

@media (max-width: <some number>px) {
  li {
    display: block;
    width: 100%;
  }
}

fiddle : https://jsfiddle.net/mkarajohn/vb16d46j/

只需调整结果 Pane 的大小即可查看效果。

关于jquery - 如果在导航栏的 CSS 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35972289/

相关文章:

javascript - jquery 平滑滚动不正确的结果

javascript - 将新属性附加到对象中的特定位置

jquery - 循环遍历具有特定类的 div 中的所有输入

jquery - CSS 问题 - 我希望客户区完全填满

jquery - 链接在 UI 可选内部不起作用

html - 无法弄清楚为什么侧边栏不会与顶部的主要内容对齐

html - 固定元素内的垂直/水平居中

javascript - 这是 jquery 的跨域问题吗?

css - 'npm run prod' 输出错误

css - 在 jumbotron 类中自动调整非常长的文本