【div+css】两个div,如何让内层的div在外层div中水平垂直居中
好久没有写样式,很是很生疏
====================================================================
方法1:
.parent {width:800px;height:500px;border:2px solid #000;position:relative; }.child {width:200px;height:200px;margin: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0; background-color: red; }
方法2:
.parent {width:800px;height:500px;border:2px solid #000;display:table-cell;vertical-align:middle;text-align: center;}.child {width:200px;height:200px;display:inline-block;background-color: red;}
方法3:
.parent {width:800px;height:500px;border:2px solid #000;display:flex;justify-content:center;align-items:center;}.child {width:200px;height:200px;background-color: red;}
方法4:
.parent {width:800px;height:500px;border:2px solid #000;position:relative;}.child {width:300px;height:200px;margin:auto;position:absolute;/*设定水平和垂直偏移父元素的50%,再根据实际长度将子元素上左挪回一半大小*/left:50%;top:50%;margin-left: -150px;margin-top:-100px;background-color: red;}
转载于:https://www.cnblogs.com/sxdcgaq8080/p/7723751.html
【div+css】两个div,如何让内层的div在外层div中水平垂直居中相关推荐
- css图片在盒子里居中,让图片在div盒子中水平垂直居中
//调整多张图片,让图片水平垂直居中 function adjustImg(){ let imgDiv = document.getElementsByClassName("img" ...
- DIV+CSS两种盒子模型(W3C盒子与IE盒子)
在辨析两种盒子模型之前.先简单说明一下什么叫盒子模型. 原理: 先说说我们在网页设计中常听的属性名:内容(content).填充(padding).边框(border).边界(margin), CSS ...
- 如何使img或者div在div中水平垂直居中显示
闲来无事,被人问到如何使img在一个div中垂直居中显示,自己就总结了如下几种方法,供大家参考: 方法一:在box中添加span空元素 <div id="box">&l ...
- div在body中水平垂直居中
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- CSS的12中水平垂直居中方法
文章目录 一.水平垂直居中的12种方法 1.absolute + 负margin 2. absolute + margin:auto 3.absolute + calc 4.absolute + tr ...
- 后端开发工程师的DIV+CSS两栏布局入门
padding 导致 width 扩大 如果对一个元素同时指定了 width 和 padding, 那么它实际的宽度是 padding-left + padding-right + width, 所以 ...
- 让行内元素(如图片)在div中水平垂直居中 (干货)
(1)第一种:用vertical-align <div class="method1"><span class="tiptop">< ...
- 一个div在另一个div中水平垂直居中
<meta charset="UTF-8"> <title>div居中</title> </head><style> . ...
- CSS:仅对子盒子修饰样式,三种让其在父盒子中水平垂直居中的方法及其优缺点(父盒子宽高未知)
1.给父盒子相对定位,子盒子绝对定位,left,top,right和bottom,都设置为0: position: absolute; left: 0; right: 0; top: 0; botto ...
- html css样式div属性,div css
DIV+CSS是WEB设计标准,它是一种网页的布局方法.与传统中通过表格(table)布局定位的方式不同,它可以实现网页页面内容与表现相分离.提起DIV+CSS组合,还要从XHTML说起.XHTML是 ...
最新文章
- R语言ggplot2可视化为组合图添加综合图例实战:使用ggpubr包ggarrange函数实现综合图例、使用patchwork包实现综合图例
- SAP SD基础知识之装运的组织单元(Organizational Units in Shipping)
- linux]ubuntu挂载U盘
- 大学计算机无线论文范文大全,大学计算机论文范文
- mysql insert 失败_mysql insert语句出错
- 朴素贝叶斯趣味挑战项目
- python、中循环功能可通过什么命令实现_python定时执行指定函数的方法 Python如何定时循环执行命令?...
- Github(2)-本地配置git
- php后台代码自动生成程序,Thinkphp自定义代码生成工具及用法说明(附下载地址)...
- c++ 传智课件_沪科版初中物理九年级全册第二节 科学探究:物质的比热容公开课优质课课件教案视频...
- 如何使用Java语言实现一个网页爬虫
- 云计算在我们日常生活中有很多应用,主要有哪些?
- 微信小程序开发工具显示网络错误
- 使用HTML制作简易求职表
- 聚类分析原理及R语言实现过程
- 华北电力计算机类哪个专业好,华北电力大学哪个专业好就业
- 【CF487E】Tourists-圆方树+multiset+树链剖分
- 我在创业游戏公司的一年
- Decorator装饰者【C++实现】
- 智能发展的四个层次:运算智能,感知智能,认知智能,强智能。道翰天琼认知智能。
热门文章
- net core文件接收(jpg、png、zip、pdf等自己设置)
- php实现并排,css实现多列并排 多块并排 左右顶头_html/css_WEB-ITnose
- Matlab函数——dct2
- OFFICE使用技术:让几个自选图形间距相等
- 删除一个空目录的JAVA代码
- ImportError: No module named _internal
- 全网首发:解决办法:shmget()一直失败,errno=-22
- LINUX安装DeepStream
- 音频格式G711转PCM的代码
- for循环批量写文件 shell_Shell脚本编程03下——Shell编程之循环语句