html - 媒体查询问题

标签 html css media-queries

我正在学习 HTMLCSS。我创建了一个站点,我需要对一件事进行媒体查询,但它不起作用:

@media screen and (max-width: 1100px) {
  #boxmb {
    position: fixed;
    left: 60%;
    padding-top: 1%;
    z-index: 999;
  }
}
<a class="boxmb" href="#section2"><img class="boxmb" id="boxmb" id="togglee" style="position: fixed; left: 90%; padding-top: 10%" src="https://placehold.it/100x100" alt="" id="image1" onclick="showButton();diffImage(this);showSurpriseImage();PlaySound();" ></a>

这是我的网站:http://rickandmorty.8u.cz/index.html

最佳答案

它不起作用,因为 inline 样式 你在 img element 中有覆盖你所有的内部/外部您为同一元素定义的样式内联样式 具有最高优先级,其次是内部外部。所以,为了解决这个问题,只需将你的内联样式移到@media之上:

#boxmb {
  position: fixed;
  left: 90%;
  padding-top: 10%;
}

@media screen and (max-width: 1100px) {
 #boxmb {
   position: fixed;
   left: 60%;
   padding-top: 1%;
   z-index: 999;
 }
}
<a class="boxmb" href="#section2">
  <img class="boxmb" id="boxmb" src="https://placehold.it/100x100" alt="" onclick="showButton();diffImage(this);showSurpriseImage();PlaySound();">
</a>

关于html - 媒体查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46834005/

相关文章:

html - CSS 类 - 字体颜色取决于值(在表格中)

css - 如何使用 bootstrap4 增加容器的最大宽度?

javascript - 针对 iPhone 5 和 5S 的纵向和横向问题

css - Bootstrap4 媒体查询直接采取移动 View 甚至在笔记本电脑上打开文件

html - 媒体查询下载

forms - 可能有两个输入的 HTML slider ?

javascript - 将单击按钮输出的文本居中

javascript - CSS 无法识别悬停颜色集

javascript - Safari 顶部、左侧过渡问题

javascript - 即使路径正确,grunt-contrib-less 也找不到源文件