方法一:
float:right
此外,浮动还会使得布局更紧凑(没空隙)
<div style="background-color: red ;width: 100%;h ei ght: 60px;/* text-align: right; */"> <div style="width: 30px;height: 100%;background-color: yellow;float: right;">hello</div> <div style="width: 60px;height: 100%;background-color: blue;float: right;">hi</div> </div>
效果图如下:
方法二:
dis play :inline-block+text-align:right
text-align:right影响的是其下的 行内元素 或文字,所以inline-block使得div具有了行内元素的特性,可以右对齐
<div style="background-color: red;width: 100%;height: 60px;text-align: right;"> <div style="width: 30px;height: 100%;background-color: yellow;display: inline-block;">hello</div> <div style="width: 60px;height: 100%;background-color: blue;display: inline-block;">hi</div> </div>
效果图如下:
从上面两个方法来看:
float的布局更为紧凑一些;
float:right会 改变 顺序,而text-align:right不会;
text-align同时会影响其下元素的文字对齐方式;
所以,综合两个方法,可以得到如下组合:
<div style="background-color: red;width: 100%;height: 60px;text-align: right;"> <div style="width: 30px;height: 100%;background-color: yellow;display: inline-block;">hello</div> <div style="width: 60px;height: 100%;background-color: blue;float: right;">hi</div> </div>
效果如下:
进一步发现,综合之后:
布局更为紧凑;
float和inline-block同行时,并不会产生覆盖浮动的现象,只是会各自规矩地排列着。
&nbs p; 到此这篇关于css下div下同行多元素右对齐的 文章 就介绍到这了,更多相关div同行多元素右对齐内容请搜索以前的文章或继续浏览下面的相关文章,希望大家以后多多支持!
总结
以上是 为你收集整理的 css下div下同行多元素右对齐 全部内容,希望文章能够帮你解决 css下div下同行多元素右对齐 所遇到的问题。
如果觉得 网站内容还不错, 推荐好友。
查看更多关于css下div下同行多元素右对齐的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did201457