我剛剛開始使用CSS,並想了解一些行爲。CSS'top'property has no effect
在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/
這些類的元素沒有絕對定位,所以添加頂部和右側不會改變任何東西。我不確定你對背景的評論意味着什麼。 – 2014-09-26 17:46:53
至少您需要添加絕對位置或相對位置或固定位置,以便頂部或底部或左側或右側影響 – 2014-09-26 17:55:12