即使width设置为0也可以

时间:2013-08-24 11:30:25

标签: html css

这似乎是一个奇怪的问题。 在这个简单的例子中,我为选择器h3设置了宽度:0。如果我使用IE 9并使用F12开发工具,我可以看到宽度实际为0但是显示在h3内的文本即使然后显然长于0也可以。有人可以解释结果如何。 / p>

<!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Chapter 5: Indestructible Boxes</title>
        <style type="text/css" media="screen">
           body 
           {
              font-family: Arial, sans-serif;
              font-size: small;
            }

            h3
            {
               background :blue;
               width:0px;
            }
        </style>
    </head>

    <body>
    <h3>Gifts and Special Offers v Gifts and Special Offers Gifts and Special 
        Offers</h3>
    </body>
 </html>

//托尼

3 个答案:

答案 0 :(得分:2)

添加overflow: hidden;

h3
{
   background :blue;
   width:0px;
   overflow:hidden;
}

答案 1 :(得分:1)

通常,宽度不是&lt;的有效属性。 H3&GT;标签。 要隐藏它,请使用:

h3
{
   display: none;
}

答案 2 :(得分:0)

如果你想隐藏h3的文字你可以使用

 h3
        {
           background :blue;
           width:0px;

          overflow:hidden
        }

     h3
            {
               background :blue;
               width:0px;
               display:none
        }