【HTML】div居中显示
方法1:
.parent {
width:800px;
height:500px;
border:2px solid #000;
position:relative;
}
.child {
width:200px;
height:200px;
margin: auto;
position: absolute;
top:; left:; bottom:; right:;
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;
}
【HTML】div居中显示的更多相关文章
- 设置div中的div居中显示
设置div中的div居中显示 方法一. <div class='big'> <div class='small'>box1</div> </div> s ...
- DIV居中显示
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 让几个横向排列的浮动子div居中显示的方法
div设置成float之后,就无法使子div居中显示了,那么如何让几个横向排列的浮动的div居中显示呢,下面有个不错的方法,希望对大家有所帮助 div设置成float之后,在父div中设置text-a ...
- 多个div居中显示
页面中有多个div时我们希望并排居中显示,可以通过在并排显示的div上一层再加一个div,设定宽度,然后让其居中显示达到需要的效果. 关键是要对外层div设定宽度. <!DOCTYPE html ...
- css div居中显示的4种写法
Demo:http://www.feman.cn/h5/center.html .absolute 绝对定位 这是我们最常用的一种居中定位写法 要求必须确定div的宽高度 目前市面上的浏览器基本上都支 ...
- 不固定宽度的div居中显示
对于div的居中 ,如果是有固定宽高的,可以加margin:auto;水平垂直居中,但如果是不固定宽高,又想让div居中的话,这种方式都可能不奏效,达不到想要的效果. 有两种方法:1.加display ...
- div 居中显示
<html lang="en"> <head> <meta charset="UTF-8"> <title>di ...
- 使用inline-block,使前面img,后面空div居中显示在一行后,导致当div中有内容时,div下移问题
.pro_li img,.pro_sm{display: inline-block; *display:inline;*zoom:1;vertical-align: middle ;} 解决方法:使用 ...
- 【转】div居中代码 DIV水平居中显示CSS代码
原文地址:http://www.divcss5.com/rumen/r622.shtml 如何使用CSS让DIV居中显示,让div水平居中有哪些CSS样式呢? 需要的主要css代码有两个,一个为tex ...
随机推荐
- Multi-cloud Kubernetes with Triton
https://www.joyent.com/blog/triton-kubernetes-multicloud While running an experimental Kubernetes cl ...
- python-zip方法
zip 返回一个将多个可迭代对象组合成一个元组序列的迭代器. 1. 循环多个list的数据: letters = ['a', 'b', 'c'] nums = [1, 2, 3] for lette ...
- 《转》冯森林:手机淘宝中的那些Web技术(2014年)
Native APP与Web APP的技术融合已经逐渐成为一种趋势,使用标准的Web技术来开发应用中的某些功能,不仅可以降低开发成本,同时还可以方便的进行功能迭代更新.但是如何保证Web APP的流畅 ...
- VirtualBox与VMWare网络冲突
VirtualBox安装一个XP后,发现老是上不到网,怎么折腾都不行, 后来发现设备管理器中 vmware accelerated amd pcnet adapter #2显示黄色感叹号 不对呀,这是 ...
- 【delphi】Byte数组与String类型的转换
string string = AnsiString = 长字符串,理论上长度不受限制,但其实受限于最大寻址范围2的32次方=4G字节: 变量Str名字是一个指针,指向位于堆内存的字符序列,字符序列起 ...
- type、object和class的关系
- 1. AutoEncoder介绍
1. AutoEncoder介绍 2. Applications of AutoEncoder in NLP 3. Recursive Autoencoder(递归自动编码器) 4. Stacked ...
- C# using关键字 --转
其实对于.NET的学习者一开始都接触using这个关键字了,可能大家没有怎么在意,包括我本人也是的,直到今天有人问我using的作用时,才引起了我的注意. 概况来说可以分为两种:第一种,就 ...
- 愿Linux红帽旋风吹得更加猛烈吧!
大约在2000年年初.<中国青年出版社>准备从台湾引进图书(中译本)"Linux红帽旋风"(美国Robert Young),让我为该书写一个前言. 该书作者罗伯特.扬是 ...
- kafka 怎么保证的exactly once
Kafka auto.offset.reset值详解 发表于2017/7/6 11:25:22 1010人阅读 分类: Kafka 昨天在写一个java消费kafka数据的实例,明明设置auto.o ...