HTML中如何让两个div并排显示,举个例子

在HTML中让两个div并排显示,通常情况下有三种实现方式,包括:
https://zhidao.baidu.com/question/135016260138604645.html
(1)设置为行内样式,display:inline-block

(2)设置float浮动
(3)设置position定位属性为absolute

以下为三种方式的具体实现代码:

1、设置每个div的展现属性为行内样式,示例代码为:

<div class="app">

<div style="display:inline-block;background:#f00;">div1</div>

<div style="display:inline-block;background:#0f0;margin-left:10px;">div2</div>

</div>

2、设置float浮动,示例代码为:

<div class="app">

<div style="float:left;background:#f00;">div1</div>

<div style="float:left;background:#0f0;margin-left:10px;">div2</div>

</div>

3、设置position定位属性为absolute, 示例代码为:

div1
div2
扩展资料: css清除浮动方法

(1)添加新的元素 、应用 clear:both

.clear {

clear: both; 
height: 0;

height: 0;
overflow: hidden;
}

(2)父级div定义 overflow: auto

.over-flow {
overflow: auto;

zoom: 1; //处理兼容性问题
}
(3)伪类  :after 方法  outer是父div的样式

.outer { zoom:1; }    /*==for IE6/7 Maxthon2==*/

.outer :after {

clear:both;

content:'.';

display:block;

width: 0;

height: 0;

visibility:hidden; 

}
  • 6
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值