如何仅将CSS应用于顶级元素 [英] How to apply css to top level element only
本文介绍了如何仅将CSS应用于顶级元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的HTML中,我在单独的部分中有一些页脚元素,然后是该页面的一个全局页脚元素.我只想使全局页面页脚显示在视口的底部.
In my HTML I have some footer elements within separate section, and then one global footer element for the page. I want to make only the global page footer to appear on the bottom of the viewport.
如果我这样做,它将影响所有页脚:
If I do this, it will affect all the footers:
footer {
position: fixed;
bottom: 0px;
}
如果我这样做,它可以按预期工作,但是body
语法看起来很笨拙:
If I do this, it works as expected, but the body
syntax looks akward:
body > footer {
position: fixed;
bottom: 0px;
}
是否有更好的方法仅指定顶级页脚?
Is there a better way to specify top-level footer only?
推荐答案
将一个类添加到页脚中,然后将CSS应用于该特定类.
正如其他人指出的那样,body > footer
并没有错.
Add a class to to your footer and apply your css to that particular class.
As others pointed out there's nothing wrong with body > footer
though.
这篇关于如何仅将CSS应用于顶级元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文