html - CSS - 媒体查询无法正常运行

标签 html css media-queries

在我的元素中,我有一个 div,我想在屏幕达到一定大小时移动它的位置。我尝试通过媒体查询来执行此操作,但是无论屏幕大小如何,表单仍然停留在一个位置。

这是我的代码:

.formContainer {
  position: relative;
  border: 1px solid #e0e0e0;
  width: 400px;
  height: 550px;
  margin-left: 768px;
  margin-top: 140px;
}

@media screen and (max-width: 1200px) {
  .formContainer {
    background-color: red;
  }
}
<div class="formContainer">
  ....
</div>

HTML:

<div class="formContainer">
 ....
</div>

CSS:

.formContainer {
  position: relative;
  border: 1px solid #e0e0e0;
  width: 400px;
  height: 550px;
  margin-left: 768px;
  margin-top: 140px;
}

@media screen and (max-width: 1200px) {
    .formContainer {
      left: 10px;
    }
  }

更新:

@media screen and (max-width: 1200px) {
    .formContainer {
      left: -10000px;
    }
  }

更新 2:

@media screen and (max-width: 1200px) {
    .formContainer {
      background-color: red;
    }
  }

代码:

<div class="formContainer">
  <div class="innerContainer">
  </div>

  <img class="test233" src="{% static 'mosque.png' %}" width="70px" style="position: relative; top: -75px; left: 60px;">
  <span style="position: relative; top: -60px; left: 60px; font-size: 32px; font-family: serif;" class="innerText"> Islamagram </span>

    <h2 style="position: relative; font-size: 21px;left:62px; font-family: sans-serif; color: #999999; top: -46px;">&nbsp;Sign up to view and share<br>life-changing islamic content.</h2>

  <form class="form" method="post" autocomplete="off">
    {% csrf_token %}
    {% for field in form %}
      {{ field  }}
      <br>
    {% endfor %}
    <button type="submit"class="btn btn-primary subButton"><span class="signupText">Sign Up</span></button>
  </form>
  {% if error1 %}
    <span style="position: relative; color: red; font-size: 18px; left: 69px; top: 10px;">{{  error1 }}<span>
  {% endif %}
  {% if error2 %}
    <span style="position: relative; color: red; font-size: 18px; left: 68px; top: 10px;">{{  error2 }}</span>
  {% endif %}
  {% if error3 %}
    <span style="position: relative; color: red; font-size: 18px; left: 118px; top: 10px;">{{  error3 }}</span>
  {% endif %}
  {% if error4 %}
    <span  style="position: relative; color: red; font-size: 18px; left: 84px; top: 10px;">{{  error4 }}</span>
  {% endif %}

有人知道这个问题吗?谢谢。

最佳答案

.formContainer {
  position: relative;
  border: 1px solid #e0e0e0;
  width: 400px;
  height: 550px;
  margin-left: 768px;
  margin-top: 140px;
}

@media screen and (max-width: 1200px) {
    .formContainer {
      left: -200px;
    }
  }

关于html - CSS - 媒体查询无法正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58962084/

相关文章:

html - 具有相同类别的所有 sibling 的 css 选择器

css - LESS:您可以将 CSS 选择器与媒体查询组合在一起吗?

javascript - 正则表达式:如何从字符串中获取时间

javascript - 页脚使用https://www.tesla.com/charging使用什么方法?

jquery - 如何在横幅前设置图片?

javascript - 使用 react-responsive 动态设置 React Media Queries

php - CSS:动态类/属性和媒体查询——如何解决这个难题?

jquery - HTML 元素滚动条定位

javascript - 我怎样才能使这个 div 使用 jQuery 从顶部向下滑动?

jquery - 如何删除此 codepen 移动示例中提出的自定义滚动