Image is not clickable inside anchor only in IE7

后端 未结 12 1662
孤城傲影
孤城傲影 2021-02-04 05:16

Html Structure


      
   
   
    Some text 
<         


        
12条回答
  •  耶瑟儿~
    2021-02-04 06:06

    CSS Only Solution

    Tomas-I modified your fiddle into a working example. I changed your code to use a span inside the a tag because it is invalid to have a standard block level element (a div) in an inline element (an a tag). Giving the a tag layout (I used inline-block) and then setting a position:relative on that span with a z-index: -1 pushes the span "below" the a tag and makes IE7 recognize the a tag as active again. Below is the modified code used in my fiddle. You might want to set up a more generic class name than my ie7AFix (you probably will also want to just target IE7 for those CSS properties that are necessary for it only). I assume you are varying the width and height by images, and hence why you have those as inline styling.

    HTML

    
      
        
      
    
    

    CSS

    a.ie7AFix {
        display: inline-block; /*needs to set hasLayout; zoom: 1, etc.*/
    }
    
    .ie7AFix span {
        border: solid #666 4px;
        display: block;
        position: relative;
        z-index: -1;
        line-height: 0; /*this made it "cross browser" eliminating extra bottom space*/
    }
    
    .ie7AFix img { border: 1px solid red; }
    

    Updated Fiddle with line-height added to make "cross browser" if one does not want to target IE7 only. I kept the width and height in the span html above, only because the original question (by both gviswanathan and Tomas) requested it. If you don't need to set the dimensions on the span for some reason, but are simply trying to do a double border on the image, then thirtydot's answer given in the comment's below is much simpler.

提交回复
热议问题