用 class 覆盖 li 样式
在我的网站中,我创建了这个 html/css
li
{
float: left;
...
}
.myclass
{
float: right;
...
}
<ul>
<li>test 1</li>
<li class="myclass">test 2</li>
</ul>
两个列表元素具有相同的样式,但第二个不使用该类来覆盖左侧浮动。为什么?
编辑: 似乎如果我使用
li.myclass
{
float: right;
...
}
它就可以了,但我也在 div 中使用 myclass,因为它是一个常见的样式类。在不使用 li. 的情况下如何解决该问题?
in my site I created this html/css
li
{
float: left;
...
}
.myclass
{
float: right;
...
}
<ul>
<li>test 1</li>
<li class="myclass">test 2</li>
</ul>
The two list elements have the same style but the second doesn't use the class to override the left float. Why?
EDIT:
it seems that if I use
li.myclass
{
float: right;
...
}
it works but I'm using myclass also in divs because it's a common style class. How can I fix the problem without use li.?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您的帖子所述,如果您使用更“特定”的选择器(例如 li.myclass),则可以覆盖 float 属性。因此,您可以在逗号分隔的列表中列出两个选择器。
或者您可以使用
!important
覆盖该属性。此外,它还影响属性在 CSS 中显示的位置。文件中位于较低位置的属性可以覆盖上面的属性。
As your post says, you're able to overwrite the
float
-property if you use a more "specific" selector, such asli.myclass
. So you could list the two selectors in a comma-seperated list.Or you can use
!important
to overwrite the property.Also, it plays a role at which position in your CSS the property shows up. Properties that are located lower in the file can overwrite properties which are above.
根据您的评论,我认为您应该使用一张桌子,因为它看起来很像成为一张桌子。只要表格不习惯设计工作,它就不是邪恶的。
或者,如果您确实想避免使用表格,只需创建两个列表并将 ' 与 float 对齐即可。
Coming from your comment, I think you should use a table, as it seems pretty much like becoming one. Tables are not evil as long as they aren't getting used to to design-work.
Or if you really want to avoid tables, just do two lists and align the 's with float.