Search code examples
htmlcssinternet-explorerwidthinternet-explorer-7

IE7 width:auto issue


CSS

    #wrapper .tn{
      width:auto;
      height:20px;
      line-height:20px;
      float:left;
      padding:5px 2px 5px 5px;
      margin:0 5px 10px;
      font-weight:bold;
      background:#f0f0f0;
    }

HTML

    <div id="wrapper">
        <div class="tn">Text</div>
        <div class="tn">Text</div>
        <div class="tn">Text</div>
    </div>

Above codes work smooth in FF,Chrome,Safari,Opera,IE9,IE8 . But there is problem for IE7. Div doesn't expand according to text.It cover wrapper div as width. How can I fix this?


Solution

  • Seems fine to me, checked using IE7 developers tools, you can try display: inline-block; instead of float

    #wrapper .tn{
      height:20px;
      line-height:20px;
      padding:5px 2px 5px 5px;
      margin:0 5px 10px;
      font-weight:bold;
      background:#f0f0f0;
      display: inline-block;
    }