gpt4 book ai didi

html - CSS 'top' 属性无效

转载 作者:行者123 更新时间:2023-11-28 17:31:13 25 4
gpt4 key购买 nike

我刚开始接触 CSS,想了解一些行为。

我在 CSS 文件中定义了这个:

#spa {
position : absolute;
top : 8px;
left : 8px;
bottom : 8px;
right : 8px;

min-height : 500px;
min-width : 500px;
overflow : hidden;

background-color : #fff;
border-radius : 0 8px 0 8px;
}

.spa-shell-head {
top : 0;
left : 0;
right : 0;
height : 40px;
}
.spa-shell-head-logo {
**top : 4px;
left : 4px;**
height : 32px;
width : 128px;
background : orange;
}

.spa-shell-head-acct {
**top : 4px;
right : 0;**
width : 64px;
height : 32px;
background : green;
}

在我的 HTML 文件中:

<body>
<div id="spa">
<div class="spa-shell-head">
<div class="spa-shell-head-logo"></div>
<div class="spa-shell-head-acct"></div>
<div class="spa-shell-head-search"></div>
</div>
<div class="spa-shell-main">
<div class="spa-shell-main-nav"></div>
<div class="spa-shell-main-content"></div>
</div>
<div class="spa-shell-foot"></div>
<div class="spa-shell-chat"></div>
<div class="spa-shell-modal"></div>
</div>
</body>

为什么我可以将粗体属性更改为任意数字,但元素却没有改变? (至少我为那些元素设置的背景颜色)

完整代码可以在这里找到:http://jsfiddle.net/fu6dmhdt/1/

最佳答案

因为 .spa-shell-head-logo.spa-shell-head-acct div 都没有定位。

CSS top, right, bottom and left (offset) 属性只适用于非static position 元素 - 即元素具有 position 而不是 static (fixed绝对相对)。

比如给他们一个relative的位置看看效果- Example .

关于html - CSS 'top' 属性无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26065363/

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