gpt4 book ai didi

html - 为什么使用属性固定元素会改变它的大小?

转载 作者:太空宇宙 更新时间:2023-11-04 12:57:01 25 4
gpt4 key购买 nike

我有一个宽度相同的表格,但我需要固定标题,所以我在标题处使用了这个属性(固定),但哦惊喜!当我使用这个属性时,标题会改变它的大小,现在比表格的其他部分小......就像表格现在是包装内容(就像在 android 属性中一样)并且如果我删除属性:固定行我header 的宽度与表格的其余部分相同,如何使用 fixed 而不会丢失原来的宽度?

我的家

th{
position: fixed;
top: -90px;
font-family: 'Open Sans', sans-serif;
font-size: 30px;
height: 20px;
background-color: white;
color: #525552;
text-align: center;
}

和我的 tds

td{
border: 2px solid #525552;
width: 164.7px;
margin-top: 50px;
font-family: 'Open Sans', sans-serif;
}

最佳答案

你不能!

position:fixed 元素不受页面上任何其他元素的影响,而仅受视口(viewport)影响:

MDN Definition

Fixed positioning is similar to absolute positioning, with the exception that the element's containing block is the viewport.

因此,如果将位置设置为fixed,就不能再继承父级的宽度(在本例中为表格)

关于html - 为什么使用属性固定元素会改变它的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25747078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com