首页 > 解决方案 > 如何正确放置位置 css?

问题描述

我有一个重量为 100% 的 < div > 并且应该在右侧放置一个按钮。但是我的代码不起作用。谁能帮我找出原因?

<div style="width:100%">
   <span>some text</span>
   <input style="position:relative; right:0px;" type="button"/>
</div>

标签: cssposition

解决方案


div 必须是相对的,按钮是绝对的。

 <div style="width:100%; position: relative;">
    <span>some text</span>
    <input style="position:absolute; right: 0px;" type="button"/>
 </div>

推荐阅读