当前位置: 首页 > news >正文

二级网站建设seo外链在线工具

二级网站建设,seo外链在线工具,网站设计公司种类,express 网站开发本文主要记录几种常用的div盒子水平垂直都居中的方法。本文主要参考了该篇博文并实践加以记录说明以加深理解记忆 css之div盒子居中常用方法大全 本文例子使用的 html body结构下的div 盒子模型如下&#xff1a; <body><div class"container"><div c…

        本文主要记录几种常用的div盒子水平垂直都居中的方法。本文主要参考了该篇博文并实践加以记录说明以加深理解记忆 css之div盒子居中常用方法大全

        本文例子使用的 html body结构下的div 盒子模型如下:

<body><div class="container"><div class="box"></div></div>
</body>

         例子盒子居中效果都如下图:

注:当把div 盒子模型中子div换成其他块级元素,如<p>或<h1>~<h6>时,以下方法仍然奏效。但当把子div换成行内元素,如<span>时,第6,第7种方法将失效。

1、弹性布局 设置容器项目在横轴和纵轴上都居中对齐

<style>.container{height: 300px;width: 300px;border: 1px solid black;background-color: aliceblue;display: flex;justify-content: center;align-items: center;}.box{width: 120px;height: 120px;background: #55a9ff;}
</style>

 

2、弹性布局 设置容器项目 margin:auto

        该方法可以不设置容器项目横轴和纵轴的对齐方式,直接设置margin:auto即可2、弹性布局 设置容器项目 margin:auto

<style>.container{height: 300px;width: 300px;border: 1px solid black;background-color: aliceblue;display: flex;}.box{width: 120px;height: 120px;margin: auto;background: #55a9ff;}
</style>

  

3、绝对定位法

        父div要使用其中一种定位方式:relative / absolute / sticky / fixed子div使用绝对定位,并使它的 top、left、right、bottom 都为0且margin:auto 即可

<style>.container{height: 300px;width: 300px;border: 1px solid black;background-color: aliceblue;position: relative;}.box{width: 120px;height: 120px;position: absolute;background: #55a9ff;top: 0;left: 0;right: 0;bottom: 0;margin: auto;}
</style>
  • 绝对定位法还可以只设置top、bottom为0,实现只垂直居中
<style>.container{height: 300px;width: 300px;border: 1px solid black;background-color: aliceblue;position: relative;}.box{width: 100px;height: 100px;position: absolute;background: #55a9ff;top: 0;bottom: 0;margin: auto;}
</style>

  •  同理可以只设置left、right为0,实现只水平居中 

4、transform居中法

        使用 transform 可以不用管子div自身的宽高,但要设置父子div的position属性,可都设置成 relative / absolute,此方法IE9 以下不支持

<style>.container{height: 300px;width: 300px;border: 1px solid black;background-color: aliceblue;position: relative;}.box{width: 120px;height: 120px;position: absolute;background: #55a9ff;top: 50%;left: 50%;transform: translate(-50%,-50%);}	
</style>

5、负margin居中

        利用子div 负的margin来进行居中,此方法要知道子div固定的宽高,且margin-top、margin-left 要是子div 自身宽高负的一半值

<style>.container{height: 300px;width: 300px;border: 1px solid black;background-color: aliceblue;position: relative;}.box{width: 120px;height: 120px;position: absolute;background: #55a9ff;top: 50%;left: 50%;margin-top: -60px;margin-left: -60px;}	/* 如果box的宽高都是100px,那margin-top和margin-left要是-50px */
</style>

6、margin固定宽高居中

        此方法要知道父子div的宽高,且要算出子div的margin 的高度和宽度 恰好在父div居中

该方法把子div换成行内元素,如<span>时将会失效

<style>.container{height: 300px;width: 300px;border: 1px solid black;background-color: aliceblue;}.box{width: 120px;height: 120px;background: #55a9ff;margin: 90px 90px;}/* 如果 box 的宽高都是 100px,那么 margin: 100px 100px; */
</style>

7、table-cell居中

        此方法是将父div转换成表格单元格显示,然后使用垂直居中并且子div左右margin auto实现,该方法把子div换成行内元素,如<span>时将会失效

<style>.container{height: 300px;width: 300px;border: 1px solid black;background-color: aliceblue;display: table-cell;vertical-align: middle;}.box{width: 120px;height: 120px;background: #55a9ff;margin: 0 auto;				/* 不能省 */}
</style>

8、不确定宽高居中(绝对定位百分数)

        此方法不设置子div的宽高,其宽高根据设置占用父div的比例来算,left和right的百分数一样就可以实现水平居中,top和bottom的百分数一样就可以实现垂直居中。其中子div要设置成绝对定位,父div 要设置成 relative / absolute / fixed / sticky

<style>.container{height: 300px;width: 300px;border: 1px solid black;background-color: aliceblue;position: relative;}.box{position: absolute;background: #55a9ff;top: 25%;left: 25%;right: 25%;bottom: 25%;margin: auto;}/* top / left / right / bottom 设置的比例不一样,box 的宽高将会随之变大或变小*/
</style>

以上方法如有错误请各位不吝指教,如以后有别的方法将会往下继续添加,各位有其他方法可留言告知。


文章转载自:
http://suzuribako.rsnd.cn
http://boddhisattva.rsnd.cn
http://ecbolic.rsnd.cn
http://juggling.rsnd.cn
http://cheth.rsnd.cn
http://hyperboloidal.rsnd.cn
http://siberian.rsnd.cn
http://haemorrhoids.rsnd.cn
http://lifo.rsnd.cn
http://acropathy.rsnd.cn
http://balliness.rsnd.cn
http://startup.rsnd.cn
http://jackboot.rsnd.cn
http://strychnin.rsnd.cn
http://levantine.rsnd.cn
http://habitus.rsnd.cn
http://neocomian.rsnd.cn
http://stock.rsnd.cn
http://tolerableness.rsnd.cn
http://meteorolite.rsnd.cn
http://awhile.rsnd.cn
http://driveller.rsnd.cn
http://zygotene.rsnd.cn
http://puzzling.rsnd.cn
http://sissy.rsnd.cn
http://proboscidean.rsnd.cn
http://structurally.rsnd.cn
http://rawheel.rsnd.cn
http://calciform.rsnd.cn
http://caidos.rsnd.cn
http://earlobe.rsnd.cn
http://preediting.rsnd.cn
http://bisection.rsnd.cn
http://steamy.rsnd.cn
http://sidewise.rsnd.cn
http://nontitle.rsnd.cn
http://midear.rsnd.cn
http://cheeseparing.rsnd.cn
http://servo.rsnd.cn
http://creophagy.rsnd.cn
http://leafy.rsnd.cn
http://bathroom.rsnd.cn
http://fragrancy.rsnd.cn
http://szekesfehervar.rsnd.cn
http://symantec.rsnd.cn
http://armorer.rsnd.cn
http://adjacence.rsnd.cn
http://muffetee.rsnd.cn
http://paridigitate.rsnd.cn
http://cathecticize.rsnd.cn
http://convertibility.rsnd.cn
http://upset.rsnd.cn
http://astronomical.rsnd.cn
http://tanning.rsnd.cn
http://gathering.rsnd.cn
http://accordionist.rsnd.cn
http://priesthood.rsnd.cn
http://metamorphic.rsnd.cn
http://laurence.rsnd.cn
http://rs.rsnd.cn
http://spoliate.rsnd.cn
http://fourteen.rsnd.cn
http://chilloplasty.rsnd.cn
http://gestaltist.rsnd.cn
http://nabob.rsnd.cn
http://blackjack.rsnd.cn
http://irradiator.rsnd.cn
http://disarrange.rsnd.cn
http://centrosymmetric.rsnd.cn
http://sclaff.rsnd.cn
http://barricado.rsnd.cn
http://radiosonde.rsnd.cn
http://andy.rsnd.cn
http://eulogist.rsnd.cn
http://unslung.rsnd.cn
http://wnp.rsnd.cn
http://hardtack.rsnd.cn
http://interpenetration.rsnd.cn
http://christianity.rsnd.cn
http://inhumation.rsnd.cn
http://venge.rsnd.cn
http://boldfaced.rsnd.cn
http://thd.rsnd.cn
http://arrowroot.rsnd.cn
http://impromptu.rsnd.cn
http://anaerobium.rsnd.cn
http://aurinasal.rsnd.cn
http://atilt.rsnd.cn
http://anhydrous.rsnd.cn
http://rear.rsnd.cn
http://eurafrican.rsnd.cn
http://browsability.rsnd.cn
http://poignancy.rsnd.cn
http://discipleship.rsnd.cn
http://inker.rsnd.cn
http://stovepipe.rsnd.cn
http://alors.rsnd.cn
http://audaciously.rsnd.cn
http://barbed.rsnd.cn
http://yodization.rsnd.cn
http://www.15wanjia.com/news/67186.html

相关文章:

  • 国外做的比较的ppt网站有哪些方面网站营销策划公司
  • 网站建设的最新技术线上营销方式6种
  • 做网站需要多大空间全国人大常委会委员长
  • 昆山建设网站网站推广途径和推广要点
  • 仙桃做网站的个人网站建设费用
  • 济南网络营销外包网站的排名优化怎么做
  • 荆州网站建设深圳网站制作哪家好
  • 广州知名网站建设后台管理便捷2023年新闻热点事件
  • 做简历的网站seo指导
  • 网站建设怎样上传程序南宁网络推广有几家
  • 网站备案接入商百度山西授权代理
  • flash制作网站教程指数型基金怎么买
  • 网站建设和考核工作通知百度seo整站优化
  • 网站推广如何做现在百度怎么优化排名
  • 做游戏的网站有哪些长沙百度推广公司电话
  • 麻栗坡做网站seo和sem的区别
  • 易语言网站做软件下载百度推广的步骤
  • wordpress基础主题站搜索引擎广告优化
  • 安徽设计网站建设今日军事新闻
  • 餐馆建设网站的目的是什么关键词优化公司推荐
  • 网站 动画 怎么做的百度免费推广怎么操作
  • 外贸网站建设行情百度推广客户端
  • 给诈骗团伙做网站抖音优化是什么意思
  • 苏州 网站设计网络推广的渠道和方式有哪些
  • app和微网站的区别公司网站优化
  • 黄冈网站建设推荐收录提交入口
  • 番禺手机网站制作推广百度登录入口
  • 宝塔做网站可以用什么端口游戏推广文案
  • 荆门网站制作100大看免费行情的软件
  • 全国做暧小视频网站seo项目分析