博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
两个div不同高度并排显示
阅读量:4583 次
发布时间:2019-06-09

本文共 1172 字,大约阅读时间需要 3 分钟。

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

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

<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>

扩展资料:

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; 

}

 

 

 

 

链接:https://zhidao.baidu.com/question/135016260138604645.html

转载于:https://www.cnblogs.com/wanlibingfeng/p/10676736.html

你可能感兴趣的文章
JWT入门简介
查看>>
结对编程——吐槽必应词典
查看>>
katalon系列八:Katalon Studio图片识别
查看>>
Spring操作指南-针对JDBC配置声明式事务管理(基于XML)
查看>>
sql server 调优----索引缺失
查看>>
spring + junit 测试
查看>>
.net core 无法获取本地变量或参数的值,因为它在此指令指针中不可用,可能是因为它已经被优化掉了...
查看>>
Poj2186Popular Cows
查看>>
TCP之listen&backlog
查看>>
实验室的毕业照
查看>>
核心编程答案(第六章)
查看>>
Spring 3.x jar 包详解 与 依赖关系
查看>>
java线程详解二
查看>>
maven项目导入依赖jar包并打包为可运行的jar包
查看>>
leecode第二十三题(合并K个排序链表)
查看>>
关于Eclipse的unsupported major minor version 51.0 错误
查看>>
2014年目标
查看>>
weblogic启动后 登陆控制台特别慢的问题
查看>>
Spring加载resource时classpath*:与classpath:的区别
查看>>
映射“DataAdapter.TableMappings”
查看>>