css 'pointer-events' property alternative for IE

前端 未结 12 1515
無奈伤痛
無奈伤痛 2020-11-22 02:45

I have a drop down navigation menu in which some of the title should not navigate to other page when clicked(these title open a drop down menu when clicked on) while others

12条回答
  •  天命终不由人
    2020-11-22 03:49

    It's worth mentioning that specifically for IE, disabled=disabled works for anchor tags:

    Contact
    

    IE treats this as an disabled element and does not trigger click event. However, disabled is not a valid attribute on an anchor tag. Hence this won't work in other browsers. For them pointer-events:none is required in the styling.

    UPDATE 1: So adding following rule feels like a cross-browser solution to me

    UPDATE 2: For further compatibility, because IE will not form styles for anchor tags with disabled='disabled', so they will still look active. Thus, a:hover{} rule and styling is a good idea:

    a[disabled="disabled"] {
            pointer-events: none; /* this is enough for non-IE browsers */
            color: darkgrey;      /* IE */
        }
            /* IE - disable hover effects */   
            a[disabled="disabled"]:hover {
                cursor:default;
                color: darkgrey;
                text-decoration:none;
            }
    

    Working on Chrome, IE11, and IE8.
    Of course, above CSS assumes anchor tags are rendered with disabled="disabled"

提交回复
热议问题