Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 内联元素的宽度正在更改,而不会使其成为块?_Html_Css - Fatal编程技术网

Html 内联元素的宽度正在更改,而不会使其成为块?

Html 内联元素的宽度正在更改,而不会使其成为块?,html,css,Html,Css,在下面的代码中: <html> <head> <style type="text/css"> ul { list-style-type:none; margin:0; padding:0; } a { display:block; width:60px; background-color:#dddddd; } </style> &

在下面的代码中:

<html>
<head>
    <style type="text/css">
    ul
    {
     list-style-type:none;
     margin:0;
     padding:0;
    }
    a
    {
     display:block;
     width:60px;
     background-color:#dddddd;
    }
 </style>
 </head>

 <body>
      <ul>
      <li><a href="#home">Home</a></li>
      <li><a href="#news">News</a></li>
      <li><a href="#contact">Contact</a></li>
      <li><a href="#about">About</a></li>
      </ul>
 </body>
 </html>

保险商实验室
{
列表样式类型:无;
保证金:0;
填充:0;
}
A.
{
显示:块;
宽度:60px;
背景色:#dddddd;
}
在这里,即使我不显示锚作为一个块,然后仍然改变它的宽度,它是在实际变化。然而,我读到:

W3C的CSS2规范规定,对于内联的、未替换的元素,“宽度”属性不适用


谁能给我解释一下,为什么会这样?Thnks…

我在Firefox、IE、Chrome和Opera中试过,如果你不将锚元素转换成块元素,它们都不会应用宽度


不过,我确实尝试过使用JSFIDLE,其中页面具有doctype。您的页面没有doctype,因此它是在“怪癖”模式下呈现的,这可能会在某些浏览器中触发异常行为。

Ya,没错,这是因为我没有提到doctype,再次犯了同样的错误,谢谢!