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
并重新测试。