Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

html - 右键对齐放置按钮(Place a button right aligned)

I use this code to right align a button.

(我使用此代码右键对齐按钮。)

<p align="right">
  <input type="button" value="Click Me" />
</p>

But P tags wastes some space, so looking to do the same with span or div.

(但是P标签浪费了一些空间,所以希望用span或div来做同样的事情。)

  ask by Sourav translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Which alignment technique you use depends on your circumstances but the basic one is float: right;

(你使用哪种对齐技术取决于你的情况,但基本的是float: right;)

:

(:)

<input type="button" value="Click Me" style="float: right;">

You'll probably want to clear your floats though but that can be done with overflow:hidden on the parent container or an explicit <div style="clear: both;"></div> at the bottom of the container.

(您可能希望清除浮点数,但可以通过overflow:hidden来完成overflow:hidden在父容器上或容器底部的显式<div style="clear: both;"></div> 。)

For example: http://jsfiddle.net/ambiguous/8UvVg/

(例如: http//jsfiddle.net/ambiguous/8UvVg/)

Floated elements are removed from the normal document flow so they can overflow their parent's boundary and mess up the parent's height, the clear:both CSS takes care of that (as does overflow:hidden ).

(浮动元素从正常的文档流中移除,因此它们可以溢出它们的父级边界并弄乱父级的高度, clear:both CSS都会处理它( overflow:hidden )。)

Play around with the JSFiddle example I added to see how floating and clearing behave (you'll want to drop the overflow:hidden first though).

(使用我添加的JSFiddle示例来查看浮动和清除行为的方式(您将要删除overflow:hidden尽管首先overflow:hidden )。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...