0

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>

上記のコードは、FF、Chrome、Safari、Opera、IE9、IE8 でスムーズに動作します。しかし、IE7には問題があります。div はテキストに従って拡張されません。ラッパー div を幅としてカバーします。どうすればこれを修正できますか?

4

2 に答える 2

1

IE7開発者ツールを使用してチェックした私には問題ないようです。display: inline-block;代わりに試すことができます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;
}
于 2012-12-24T15:37:10.053 に答える
0

I'm assuming the div you're talking about is #wrapper? #wrapper isn't expanding because you need to clear the floats

Check out the clearfix class in the HTML5 Boilerplate (https://github.com/h5bp/html5-boilerplate/blob/master/css/main.css)

.clearfix:before,
.clearfix:after {
    content: " "; /* 1 */
    display: table; /* 2 */
}

.clearfix:after {
    clear: both;
}

/*
 * For IE 6/7 only
 * Include this rule to trigger hasLayout and contain floats.
 */

.clearfix {
    *zoom: 1;
}

So do this in your code:

<div id="wrapper" class="clearfix">
    <div class="tn">Text</div>
    <div class="tn">Text</div>
    <div class="tn">Text</div>
</div>
于 2012-12-24T15:57:03.027 に答える