Remove image link in mobile screen

血红的双手。 提交于 2019-12-11 13:41:16

问题


I have a clickable image on my desktop website theme which showed on mobile screens. I’ve managed to remove the image with the following code but it has left a ‘ghost’ link which users don’t see but if touched takes them to the linked page:

In footer.tpl

<div id="footer">
<div class="column">

<a href="http://mywebsite.com/delivery" id="test"></a> 

In stylesheet.css

#test {

  @media screen and (max-width: 480px) { image display: none; }   

  background-image: url('../image/myimage.png');
  background-repeat: no-repeat;
  position: absolute;
  margin-top: 10px;
  margin-left: 20px; 
  width: 75px;
  height: 75px;

Is there any way the link could also be removed? Thanks in advance.


回答1:


Give your element a display:none; on the media query.

#test {
  display: block;
  background-image: url('../image/myimage.png');
  background-repeat: no-repeat;
  position: absolute;
  margin-top: 10px;
  margin-left: 20px; 
  width: 75px;
  height: 75px;
  background: whitesmoke; /** Testing purposes **/
}

@media all and (max-width: 480px) {
    .hide {
      display: none;
    }
}
<div id="footer">
<div class="column">
<a href="http://mywebsite.com/delivery" id="test" class="hide"></a> 



回答2:


Your CSS doesn't seem properly formed. Try replacing your media query with the following, which selects and hides your link by id:

@media screen and (max-width: 480px) {
    #test {
        display: none;
    }
}



回答3:


Right now your media query looks invalid.

To hide the link, you could do this:

@media screen and (max-width: 480px) {
  #test { 
    display: none;
  }
}

Note that this will override the display style of your #test element.

Suggestion: You may want to use a css class instead, such as <a class="hidden-mobile"... and use .test in your css file instead, so that you can reuse your class multiple times.



来源:https://stackoverflow.com/questions/31496160/remove-image-link-in-mobile-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!