Preventing an image from being draggable or selectable without using JS

前端 未结 8 2106
忘了有多久
忘了有多久 2020-12-04 05:28

Does anyone know of a way to make an image not draggable and not selectable -- at the same time -- in Firefox, without resorting to Javascript? Seems trivial, but here\'s th

8条回答
  •  借酒劲吻你
    2020-12-04 05:47

    You can use the pointer-events property in your CSS, and set it equal to 'none'

    img {
        pointer-events: none;
    }
    

    Edited

    this will block (click) event. So better solution would be

    
    
    .unselectable {
      user-drag: none; 
      user-select: none;
      -moz-user-select: none;
      -webkit-user-drag: none;
      -webkit-user-select: none;
      -ms-user-select: none;
    }
    

提交回复
热议问题