Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.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 CSS固定标题-它需要两个位置吗?_Html_Css_Position_Css Position - Fatal编程技术网

Html CSS固定标题-它需要两个位置吗?

Html CSS固定标题-它需要两个位置吗?,html,css,position,css-position,Html,Css,Position,Css Position,我看到了一些这样的例子,但我想知道在固定标题时是否有必要声明两个位置 例如,您是否需要声明top:0和左侧:0?: .header { position: fixed; top: 0; left:0; width:100%; } .header { position: fixed; top: 0; width:100%; } 或者你可以只使用top:0?: .header { position: fixed; top: 0; left:0; width:100%; }

我看到了一些这样的例子,但我想知道在固定标题时是否有必要声明两个位置

例如,您是否需要声明
top:0
左侧:0?:

.header {
 position: fixed;
 top: 0;
 left:0;
 width:100%;
}
.header {
 position: fixed;
 top: 0;
 width:100%;
}
或者你可以只使用
top:0?:

.header {
 position: fixed;
 top: 0;
 left:0;
 width:100%;
}
.header {
 position: fixed;
 top: 0;
 width:100%;
}

我只是有点困惑,因为我已经看到了这两个例子,但如果设置
top:0,我找不到合理的解释;左:0'
是必要的/比仅
top:0更好用于固定标题?

因为您的
宽度是
100%
,所以这两种方式都不重要。但是,如果宽度不是
100%
,并且
是未定位在左上角的元素的子元素,则导航将根据父元素水平定位。(并非一直向左)

如果未声明
顶部
左侧
,默认值为
左侧:自动
顶部:自动
。左<代码>的自动表示(对于固定定位元件):

  • 如果定义了right和width,则计算左侧

  • 若“宽度”或“右侧”未定义,那个么“左侧”将根据非滚动位置的默认内容流计算,就像块元素一样

然后,如果使用
position:fixed
,则通常需要使用左/右和上/下样式

要查看差异,请使用
右边距:-100px
并将标题放在其他元素中,例如表格的第二个单元格

此处测试-您可以添加
左:0
并重新测试。