[英]How to fix the position of a button for a div
我試圖通過聲明position: Fixed;
來固定按鈕position: Fixed;
但它適用於整個頁面。 有什么解決辦法,所以按鈕固定為具有height:200px
的div。 我想要做的是針對其父項的div高度固定的按鈕。 任何幫助都一定會得到幫助。
我已經做到了
<div style="Height:200px; width:45%;">
<div style="position:fixed; top:100px; left:253px;">
<asp:Button ID="ReplyEventButton" runat="server" Text="Reply to this Ad" />
</div>
</div>
使用position: absolute
而不是fixed
。 您的父div需要具有以下position: relative
。
<div style="height:200px; width:45%; position:relative;">
<div style="position: absolute; top:100px; left:253px;">
<asp:Button ID="ReplyEventButton" runat="server" Text="Reply to this Ad" />
</div>
</div>
您是否要相對於其包含的div定位按鈕,但要稍微偏移它?
如果這是您要的,請嘗試以下操作:
<div style="height: 200px; width: 45%;">
<div style="margin-top: 100px; margin-left: 253px;">
<asp:Button ID="ReplyEventButton" runat="server" Text="Reply to this Ad" />
</div>
</div>
這將偏移元素而不將其從頁面流中刪除。
如果您希望將其與頁面流分離,請遵循easwee的建議,使用相對父級和絕對子級。
希望這可以幫助。
嘗試這樣的事情:
<div style="position: relative; Height:200px; width:45%;">
<div style="position: absolute; top:100px; left:253px;">
<asp:Button ID="ReplyEventButton" runat="server" Text="Reply to this Ad" />
</div>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.