我的HTML中有一個按鈕,我希望某些內容恰好位於該按鈕下方,並且應位於所有其他內容之上,並且不應移動任何現有內容。我怎樣才能實現它?在內容下方放置內容
1
A
回答
2
不知道你想什麼來實現的,但看看這個例子使用CSS屬性position
:
<p>Other content</p>
<button>Button Text</button><br />
<div style="position:absolute; color:red;">Absolute Text</div>
<p>Other content</p>
+0
我剛剛設置了「position:absolute」,它解決了這個問題。 – 2011-04-04 14:18:38
2
把這些內容變成一個div並使用
position:absolute;
它應該是這樣的:
<div class="wrapper" style="position:relative;">
<button ..... >
<div class="yourContent" style="position:absolute; top:10px; left:0px;">
<!-- put your content here -->
</div>
</div>
如果你想只在按下按鈕後顯示此內容,然後將其更改爲:
<div class="wrapper">
<button class="yourButton" ..... >
<div class="yourContent hidden">
<!-- put your content here -->
</div>
</div>
定義CSS樣式的樣式表,如:
.wrapper {position:relative;}
.wrapper .yourButton {position:absolute; top:0; left:0}
.yourContent {position:absolute; top:20px; left:0}
.hidden {display:none;}
然後使用Javascript(使用jQuery):
$('.yourButton').click(function(){
$('.yourContent').removeClass('hidden');
});
只是一個簡單的例子,你將不得不調整。
2
Here是CSS定位的好文章可以在alistapart上找到。
看着你的問題,如果你不是100%熟悉定位,必須閱讀。
相關問題
- 1. 如何在商店內容下放置功能內容
- 2. file_put_contents,內容之間放置內容
- 3. 保存內容與文件放內容
- 4. woocommerce側欄下方內容
- 5. 在所有內容上放置div
- 6. 在Bootstrap Popover中放置JavaScript內容
- 7. 內容下推
- 8. 播放DRM內容
- 9. 在主要內容下方放置形狀的最佳方式是什麼?
- 10. 在UIWebView中縮放內容
- 11. 將內容放在iframe上?
- 12. 設置內容
- 13. 內容配置
- 14. 把內容放在一個div類內
- 15. 在控件下方展開內容
- 16. 邊欄和內容但沒有內容隱藏在邊欄內容下
- 17. 在充當容器的WPF控件中,如何放置內容?
- 18. 內容下載到
- 19. 果園:放置內容類型
- 20. 位置:固定 - 內容消失縮放
- 21. 並排放置ul li內容
- 22. 如何在LinearLayout中以垂直方式均勻放置內容?
- 23. 如何將HTML內容放置在Flash影片上方?
- 24. 內容被下推在IE6
- 25. 將回收站視圖放置在AppBarLayout下方時未顯示內容
- 26. 如何讓我的內容在導航控制器下方以編程方式調整內容y位置
- 27. 設置WebView內容
- 28. 重置tinyMce內容
- 29. 內容配置JAVA
- 30. UIScrollview重置內容
你在客戶端代碼中使用jQuery嗎? – ExtraGravy 2011-04-04 13:41:06
是的,我正在使用jQuery。 – 2011-04-04 14:17:23