媒体查询不会调整字段集和按钮的大小

我正在尝试使用媒体查询,但是我遇到了问题。调整窗口大小时,调整窗口大小时不执行任何操作,请尝试其他选项,例如:

我有这个:

@media all and (max-width: 900px) {
  #breakdown-search-clear-button {
    margin-left: 28% !important;
  }

  #historico-incidencias{
    width: 36.1% !important; 
    margin-left: 62% !important; 
    margin-top: -27.8% !important;
  }

}

或这个

@media screen and (max-width: 900px) {
  #breakdown-search-clear-button {
    margin-left: 28% !important;
  }

  #historico-incidencias{
    width: 36.1% !important; 
    margin-left: 62% !important; 
    margin-top: -27.8% !important;
  }

}

在我的CSS文件的末尾。而且它不起作用。我先尝试使用“ @media screen”,然后尝试使用“ @media all”,但是当我调整窗口大小时,在两种情况下均不起作用。

然后,我尝试在.jso文件中放置标签,如在此示例中看到的那样:

我写这个标签:

<meta name="viewport" content="width=device-width,initial-scale=1">

然后,在标签的末尾写下:

<style>
    /* On screens that are 600px wide or less,the background color is olive */
    @media screen and (max-width: 900px) {
      #breakdown-search-clear-button {
        margin-left: 28% !important;
      }

      #historico-incidencias{
        width: 36.1% !important; 
        margin-left: 62% !important; 
        margin-top: -27.8% !important;
      }
    }
</style>

但是当我调整css文件上的窗口大小时,它什么也没做。

HTML元素:

        <div id="breakdown-search-clear-button" class="roundedButtonmin roundedButtonRight deleteBG" style="margin-left: 24% !important; margin-top: 1% !important;"></div> 

<fieldset style="width: 46.1%; margin-left: 52%; margin-top: -23%; display: inline-block; vertical-align: top;" id="historico-incidencias">
                        <legend>Histórico</legend>
                        <div id="listHistoricalIncidences"></div>
                    </fieldset>

有人可以帮助我吗?

谢谢!

crystalrainss 回答:媒体查询不会调整字段集和按钮的大小

您的媒体查询工作正常,如果您调整窗口大小,可能会看到“Histórico”再次从顶部滑落。我建议将所有css放在您的css文件中,而不是在html中放置样式,这会使您的html代码更易于阅读。

body{
  background-color:red;
}
#breakdown-search-clear-button{
  margin-left:24%;
  margin-top:1%;
  background-color:green;
  width:100px;
  height:100px;
  
}
#historico-incidencia{
  width: 46.1%; 
  margin-left: 52%; 
  margin-top: -23%; 
  display: inline-block; 
  vertical-align: top;
}
    @media screen and (max-width: 900px) {
      body{
        background-color:blue;
      }
    
#breakdown-search-clear-button {
        margin-left: 28% !important;
      }

      #historico-incidencias{
        width: 36.1% !important; 
        margin-left: 62% !important; 
        margin-top: -27.8% !important;
      }
    }
<div id="breakdown-search-clear-button">

</div>

<fieldset id="historico-incidencias">
                        <legend>Histórico</legend>
                        <div id="listHistoricalIncidences"></div>
</fieldset>

这里也是小提琴,可能更容易调整大小https://jsfiddle.net/L9fdsj04/1/ 在这种情况下,有可能看到当窗口小于901px并将背景自身定位在#breakdown-search-clear-button时,背景色通道和绿色立方体(margin-left: 28%)会发生对齐。看不到“历史记录”的原因是因为您将其定位在margin-top:-23%上,并且当前位于屏幕上方

本文链接:https://www.f2er.com/3119098.html

大家都在问