2024-03-20 10:00:03

将按钮右对齐

我使用这个代码来右对齐一个按钮。

< p align =“正确”> <input type="button" value="Click Me" /> < / p >

但是<p>标签浪费了一些空间,所以考虑对<span>或<div>做同样的事情。


当前回答

< span style = " font - family:宋体;justify-content: flex-end”> < >按钮点击我!< /按钮> < / div >

<div style = "display: flex; justify-content: flex-end">
    <button>Click me!</button>
</div>

其他回答

2019年使用弹性盒的现代方法

带div标签

< div风格= "显示:flex;justify-content: flex-end;宽度:100%;填充:0;" > <input type="button" value="Click Me"/> < / div >

带跨度标签

<跨风格= "显示:flex;justify-content: flex-end;宽度:100%;填充:0;" > <input type="button" value="Click Me"/> < / span >

另一种可能是使用一个向右的绝对定位。你可以这样做:

style="position: absolute; right: 0;"

这个解决方案依赖于Bootstrap 3,如@günther-jena所指出的

Try <a class="btn text-right">Call to Action</a>. "这样就不需要额外的标记或规则来清除浮动元素。

保持按钮在页面流中:

<input type="button" value="Click Me" style="margin-left: auto; display: block;" />

(将该样式放在.css文件中,不要使用这个HTML内联,以便更好地维护)

< span style = " font - family:宋体;justify-content: flex-end”> < >按钮点击我!< /按钮> < / div >

<div style = "display: flex; justify-content: flex-end">
    <button>Click me!</button>
</div>