[英]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.