css - 指定 css 选择器

标签 css

我有一个页脚,它有一个水平菜单。

CSS

footer {
    height:99px;
}
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    font-size: 20px;
    padding-top:26px;
}
li {
    float:right;
    width:8%;
}

我想做的是,当我制作其他菜单时,页脚菜单的 css 不会影响它。什么是有效的方法? html 只是一个基本的 <footer>标签。

最佳答案

在这种情况下,您可以使用后代关系,您说将样式应用于 footer 元素内的 ul 元素。

footer {
    height:99px;
}
footer ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    font-size: 20px;
    padding-top:26px;
}
footer ul li {
    float:right;
    width:8%;
}

如果你想更具体(如果页面中可能有多个页脚元素),你可以为页脚分配一个类,如 myfooter 然后使用类选择器也如

footer.myfooter {
}
footer.myfooter ul {
}
footer.myfooter ul li {
}

看看不同的CSS selctors

关于css - 指定 css 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24816753/

相关文章:

javascript - js如何从白变蓝?

html - 如何制作具有固定宽度列的流体网格?

css - 使用内联 CSS 保留样式和否决样式表

html - 卡片中的 Figcaption 位置 - 如何?

css - 无法为动画设置路由器导出的不透明度 [Chrome]

iphone - 在 iphone 上无缝缩放网站标题。

css - CSS 规范中的 "propagated to the viewport"是什么意思?

html - 为什么页脚不在底部

javascript - 单击后隐藏导航菜单

html - 当使用带有 flex 属性的 li 时,为什么元素不在一行中?