Is putting a div inside an anchor ever correct?

前端 未结 14 3210
孤独总比滥情好
孤独总比滥情好 2020-11-21 05:43

I\'ve heard that putting a block element inside a inline element is a HTML sin:

What we have here is a
14条回答
  •  佛祖请我去吃肉
    2020-11-21 06:22

    If you want to avoid the semantic trouble of placing divs inside anchor tags, just place the anchor tag on the same level as the divs, wrap them all with a container with position: relative, make your anchor tag position: absolute and expand it to fill the container. Also if it's not on the end of the content flow make sure you throw a z-index in there to place it above the content.

    As suggested I have added a markup code:

    And the css:

    .div__container {
      position: relative; 
    }
    .div__container a {
      position: absolute;
      top: 0;
      bottom: 0;      
      left: 0;
      right: 0;
      z-index: 999;
    }
    

提交回复
热议问题