媒体查询不能覆盖以前的样式?

问题描述

我目前正在尝试将我代码中较早的样式替换为public class Bluepolygon extends JPanel { private static final long serialVersionUID = 1L; int x,x1,y,y1; public Bluepolygon() { addMouseListener(new MouseAdapter() { @Override public void mousepressed(MouseEvent me) { x = me.getX(); y = me.getY(); } }); addMouseMotionListener(new MouseAdapter() { @Override public void mouseDragged(MouseEvent me) { x1 = me.getX(); y1 = me.getY(); repaint(); } }); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(new Color(Color.blue.getRed(),Color.blue.getGreen(),Color.blue.getBlue(),60)); int xx[] = { x1,x,x1 }; int yy[] = { y,y1,y1 }; g.fillpolygon(xx,yy,4); } public static void main(String args[]) { SwingUtilities.invokelater(() -> { Bluepolygon winapp = new Bluepolygon(); winapp.setPreferredSize(new Dimension(400,400)); JFrame frame = new JFrame(""); frame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(winapp); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }); } } 的填充,但是这样做很难。我试图将节标题仅放在桌面尺寸的中心。

我的原始section-header是这样的:

section-header

我的媒体查询如下:

  .section-header {
    padding-left: 10%;
  }

我已经使用过@media #{$desktop} { .section-header { padding-left: 0; text-align: center; } } ,但是我的导师告诉我要避免使用它。如何覆盖并进行更改?

解决方法

CSS的工作方式多种多样,并且可能变得一团糟,这就是为什么您的导师提到尽可能不使用“!important”的原因。

要注意的一件事是,如果您的版块规则位于媒体查询规则之后,它将覆盖媒体查询规则。

还要考虑特异性。您对定位的要求越具体,该规则就越重要。

快速提问。您是否在Inspect中打开了它,看看它是否还在显示?那么可能存在缓存清除问题等?

如果它在inspect元素中显示,则可能值得检查是否存在具有更高特异性的东西可以覆盖它。

很难在上面找到解决方法,但是在这里不会被接受...