【发布时间】:2020-10-15 15:52:45
【问题描述】:
我有一个分配给 span 的类。 对于桌面版本,此跨度具有顶部:-25px 和左侧:-5px。 对于移动版本,我需要将相同跨度的相同类更改为值顶部:-10px 和左侧:-3px。
如何在不使用 !important 的情况下实现这一点?下面是代码:
.display {
top: -25px;
/* Need to change the values for mobile phones. */
left: -5px;
}
@media (max-width:767px) {
.display {
top: -10px;
/* This style is not applied and overruled in browser */
left: -3px;
/* This style is not applied and overruled in browser */
}
<span id="lbTest" class="display">text</span>
<style>
</style>
【问题讨论】:
-
尝试在媒体查询中使用
span.display。 -
这行得通!谢谢你。只是好奇,在媒体查询中添加 span.display 有何不同?
-
@user2294434 它只是更清楚地指定了元素。元素指定的越多,它在样式表中的优先级就越高。我就是这么理解的。但它不会覆盖
!important。 @CraftedPod 也得到了一点,编写 css 的顺序会有所不同。 :)
标签: html css responsive-design responsive