首页 > Web开发 > 详细

在HTML中实现两个div并排显示

时间:2019-09-20 14:05:43      阅读:88      评论:0      收藏:0      [点我收藏+]

在HTML中让两个div并排显示,通常情况下有三种实现方式,包括:

(1)设置为行内样式,display:inline-block

(2)设置float浮动

(3)设置position定位属性为absolute

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

个人觉得float浮动方式比较好用。

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, 示例代码为:

<div class="app">

<div style="position: absolute;width:100px;background:#f00;">div1</div>

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

</div>

在HTML中实现两个div并排显示

原文:https://www.cnblogs.com/ming-4/p/11556028.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!