div inside anchor

前端 未结 2 420
小蘑菇
小蘑菇 2020-12-06 07:13

This doesn\'t happen all the time. A bug is not a bug if cannot be reproduced!

First, I thought this was a mistake of my young programming skills but same error appe

相关标签:
2条回答
  • 2020-12-06 07:33

    I guess your divs in links cause inconsistency in some browsers (may be your css playing here).

    "Semantics", valid markup are some buzz words.

    So why would you want DIVs in an <A> tag. You can try someting like this

    <a href="#">
           <span class="divstyle">Text 1</span>
           <span class="divstyle">Text 2</span>
    </a>
    

    then in CSS

    .divstyle { 
        display: block; //and other styles etc
     }
    
    0 讨论(0)
  • 2020-12-06 07:43

    Check your page in a HTML validator. I'm 90% sure that you can't have a <div> element inside inline elements like <a>. Even though you've set the link to display:block, it's still not allowed and the browsers may be spitting their dummy.

    What you can do is use spans instead, setting them to block:

    <style type="text/css">
      .link, .link span { display: block; }
    </style>
    <a class="link" href="example.com">
     <span>text1</span>
     <span>text2</span>
    </a>
    
    0 讨论(0)
提交回复
热议问题