你对如何定义让两个DIV横向排列的方法是否熟悉,这里和大家分享一下,主要有两种方法,一种是把display换成inline,另一种就是使用float:right属性,相信本文介绍一定会让你有所收获的。
如何定义让两个DIV横向排列
两个DIV横向排列方法一:
一般情况,默认的DIV是写一个换一行,那么如何定义两个DIV横向排列而不换行呢?
DIV默认的display属性是block。所以每一个DIV都是新的一行,现在把display换成inline就不会换新行了。
- <div styledivstyle="background-color:#ff0000;
- display:inline;">aaa</div>
- <divstyledivstyle="background-color:#ffff00;
- display:inline;">bbb</div>
两个DIV横向排列方法二:
这里使用float:right属性。float做为CSS中的一个属性定义元素向哪个方向浮动。float:right文本或图像会移至父元素中的右侧。
注意有写情况float属性必须配合width使用,否则失效。
- <tdclasstdclass="bg10">
- <divstyledivstyle="width:120px;float:right;">阅读次数:9999</div>
- <divstyledivstyle="width:200px;float:right;">发表日期:2009-09-10</div>
- </td>
- .bg10{
- background-image:url(../images/news_r6_c4.jpg);
- height:24px;
- line-height:24px;
- color:#939393;
- }
height:24px;和line-height:24px;高度一致,文字垂直居中。
【编辑推荐】