代码之家  ›  专栏  ›  技术社区  ›  Tom Gullen

CSS-ie显示不太正确

  •  0
  • Tom Gullen  · 技术社区  · 14 年前
            <div class="searchWrapper">
              <table height="100%" width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="center"><input type="text" id="searchInput" class="searchBox" /></td>
                    <td><div class="searchBtn">Search</div></td>
                </tr>
              </table>           
            </div>
    

    使用CSS:

    /* Search */
    .searchWrapper
    {
        background-image:url(../images/menuBG.jpg);
        height:45px;
        width:380px;
        background-position:bottom;
        background-repeat:repeat-x;
        background-color:#79ABC4;
    }
    
    .searchBtn
    {
        cursor:pointer;
        border:outset 1px #ccc;
        background:#999;
        color:#666;
        font-weight:bold;
        height: 26px;
        position:relative;
        top:1px;        
        width: 75px;
        background:url(../images/formbg.gif) repeat-x left top;
        margin-right: 5px;
        text-align:center;
        line-height: 27px;
        font-size: 14px;
    }
    .searchBox
    {
        width:270px;
        height:25px;
        font-size: 16px;
        border:1px solid #3C81AA;
        margin-left:5px;
        line-height: 25px;
        padding-left:10px;
        padding-right:10px;
        color: #666;
    }
    

    如果在FF中运行,它将显示“很好”,而“假”按钮将显示为与输入框相同的高度和位置。

    但在IE里,我没法让它匹配,好像是1倍的折扣。假按钮的高度有点小。我已经摆弄了好长时间了,似乎还没弄明白!

    在任何人发表评论之前,我在这里使用表格,因为它只是让垂直对齐变得容易多了。

    3 回复  |  直到 14 年前
        1
  •  1
  •   Pat    14 年前

    如果您可以选择更新HTML conditional comments 并提供一个稍微不同的CSS版本来修正高度:

    HTML

    <link rel="stylesheet" type="text/css" href="css/styles.css" media="all" />
    <!--[if IE]>
        <link rel="stylesheet" type="text/css" href="css/ie.css" media="all" />
    <![endif]-->
    

    样式.css

    .searchBtn {
        height: 26px;
    } 
    

    I. CSS

    .searchBtn {
        height: 25px;
    } 
    
        2
  •  0
  •   Alex    14 年前

    当涉及到HTML时,我建议您查看语义。那根本不应该放在桌子里。从外观上看,你使用的是一个表单作为搜索框,那么为什么不使用表单标记来标记它呢?

    我还建议您检查CSS重置,如果您还没有:

    http://meyerweb.com/eric/tools/css/reset/

    它们非常有用,可以为您提供一个很好的空白画布来开始编码。如果所有其他操作都失败,请确保您具有有效的doctype!另一个需要注意的是,IE在实现Box模型时的不同之处:

    http://www.w3.org/TR/CSS2/box.html

        3
  •  0
  •   Joel Etherton    14 年前

    您可以应用一个IE CSS黑客:

    height: 26px;
    *height: 27px;