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

开发公众号seo教程自学入门教材

开发公众号,seo教程自学入门教材,美工培训网课,ssh做网站步骤上一篇博文写了div 中元素居中的N种常用方法,那么单个html元素:div(块级元素代表),span(行内元素代表)中的文字如何水平垂直都居中呢?实现方法如下: 本文例子使用的 html…

        上一篇博文写了div 中元素居中的N种常用方法,那么单个html元素:div(块级元素代表),span(行内元素代表)中的文字如何水平垂直都居中呢?实现方法如下:

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

<body><div class="container">文字居中显示</div>
</body>

        例子居中效果都如下图:

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

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

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

        

        2、使用 table-cell 显示        

                使用 table-cell 可以实现 div 中文字的垂直居中,然后在使用text-align: center可实现水平居中

<style>.container{height: 200px;width: 200px;border: 1px solid black;background-color: aliceblue;display: table-cell;vertical-align: middle;text-align: center;}	
</style>

         3、使用 Grid 布局

                display: grid + place-items: center

<style>.container{height: 200px;width: 200px;border: 1px solid black;background-color: aliceblue;display: grid;place-items: center;}	
</style>

          4、使用 line-height

                设置line-height的值和为div的height值,实现垂直居中,使用text-align实现水平居中。该方法只能使用于单行文本,如文本超过单行,文字将会溢出。且该方法不适用于span等行内元素

<style>.container{height: 200px;width: 200px;border: 1px solid black;background-color: aliceblue;text-align: center;line-height: 200px;}	
</style>

                当多行文字时,如下:

<body><div class="container">文字居中显示文字居中显示文字居中显示</div>
</body>

        当用该方法用于span等行内元素时:为span设置的宽高将失效,因为默认情况下,行内元素无法设置宽度和高度,其宽度和高度都是由它们所包含的内容决定的。有关html块级元素、行内元素、行内块级元素的说明请看该篇博文:HTML 块级元素、行内元素和行内块级元素

<body><span class="container">文字居中显示</span>
</body>

        要想让span等行内元素也实现div的效果,使用display:block 或 display:inline-block 即可

<style>.container{height: 200px;width: 200px;border: 1px solid black;background-color: aliceblue;display: block;            /* 把span显示变成块级元素 */text-align: center;line-height: 200px;}	
</style>

        5、使用 text-align: center + padding   

               使用 text-align: center 可使文字水平居中,当没有固定高度时,使用 padding-top 和 padding-bottom 相同高度即可实现垂直居中。当要求固定高度时,先看文字的高度,然后再计算出  padding-top 和 padding-bottom 相同的高度也能实现垂直居中

<style>/* 不限定高度时,container 不设置 height 属性值使用 text-align: center + padding-top、padding-bottom 相同高度*/.container{width: 200px;border: 1px solid black;background-color: aliceblue;text-align: center;padding-top:50px;padding-bottom:50px;}
</style>

<style>/*  限定高度时(如div总高度限定 200px),container 不设置 height 属性值使用 text-align: center + padding-top、padding-bottom 要根据div高度减去文字高度再平分剩余的高度假如文字高度占20px,那么padding-top、padding-bottom 都是90px*/.container{width: 200px;border: 1px solid black;background-color: aliceblue;text-align: center;padding-top:90px;padding-bottom:90px;}
</style>

  •  组合上篇 div找那个元素居中和本篇html元素居中的方法综合实现子div在父div中居中显示并且子div中的文字居中

<head><meta charset="utf-8" /><title></title><style>.container{height: 300px;width: 300px;border: 1px solid black;background-color: aliceblue;display: flex;justify-content: center;align-items: center;}.box{width: 150px;height: 150px;background: #55a9ff;display: flex;justify-content: center;align-items: center;}</style></head>
<body><div class="container"><div class="box">文字居中显示</div></div>
</body>

        注:box 中可使用上述第1,第3,第4,第5种方法实现组合文字居中,第2种display: table-cell讲失效 

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


文章转载自:
http://berylliosis.rhmk.cn
http://antipsychotic.rhmk.cn
http://ide.rhmk.cn
http://aureola.rhmk.cn
http://eminence.rhmk.cn
http://chemoreceptivity.rhmk.cn
http://quadrumvirate.rhmk.cn
http://profitability.rhmk.cn
http://bonspiel.rhmk.cn
http://notturno.rhmk.cn
http://dimeter.rhmk.cn
http://brawler.rhmk.cn
http://flukey.rhmk.cn
http://lioncel.rhmk.cn
http://bantingism.rhmk.cn
http://sidelight.rhmk.cn
http://unmarry.rhmk.cn
http://carnival.rhmk.cn
http://cytochimera.rhmk.cn
http://eggathon.rhmk.cn
http://clicket.rhmk.cn
http://whitsun.rhmk.cn
http://accessorize.rhmk.cn
http://gulgul.rhmk.cn
http://eudiometry.rhmk.cn
http://fucked.rhmk.cn
http://larvicide.rhmk.cn
http://protanope.rhmk.cn
http://waterzooi.rhmk.cn
http://fissipedal.rhmk.cn
http://impaludism.rhmk.cn
http://partite.rhmk.cn
http://boadicea.rhmk.cn
http://indecorum.rhmk.cn
http://sententia.rhmk.cn
http://underlayment.rhmk.cn
http://subcrust.rhmk.cn
http://shareholder.rhmk.cn
http://only.rhmk.cn
http://astigmatometry.rhmk.cn
http://cabotine.rhmk.cn
http://finely.rhmk.cn
http://prakrit.rhmk.cn
http://circuit.rhmk.cn
http://inhabitation.rhmk.cn
http://senesce.rhmk.cn
http://eyestrings.rhmk.cn
http://aneurismal.rhmk.cn
http://consubstantiate.rhmk.cn
http://person.rhmk.cn
http://crossing.rhmk.cn
http://hydroformylation.rhmk.cn
http://blent.rhmk.cn
http://befell.rhmk.cn
http://weirdie.rhmk.cn
http://tapi.rhmk.cn
http://tuesday.rhmk.cn
http://shippen.rhmk.cn
http://boulter.rhmk.cn
http://metopon.rhmk.cn
http://firearm.rhmk.cn
http://brew.rhmk.cn
http://catharine.rhmk.cn
http://channels.rhmk.cn
http://bios.rhmk.cn
http://degradand.rhmk.cn
http://preschool.rhmk.cn
http://karen.rhmk.cn
http://tautosyllabic.rhmk.cn
http://unsummoned.rhmk.cn
http://scoutcraft.rhmk.cn
http://containment.rhmk.cn
http://ruttish.rhmk.cn
http://fastidiously.rhmk.cn
http://memorability.rhmk.cn
http://organotherapy.rhmk.cn
http://configuration.rhmk.cn
http://consonantal.rhmk.cn
http://pug.rhmk.cn
http://democratize.rhmk.cn
http://remise.rhmk.cn
http://dysprosody.rhmk.cn
http://atomarium.rhmk.cn
http://unbusinesslike.rhmk.cn
http://claim.rhmk.cn
http://doomsten.rhmk.cn
http://pentamer.rhmk.cn
http://informatory.rhmk.cn
http://biconcave.rhmk.cn
http://guthrun.rhmk.cn
http://grandfather.rhmk.cn
http://vaccinotherapy.rhmk.cn
http://infold.rhmk.cn
http://proband.rhmk.cn
http://gazabo.rhmk.cn
http://netherward.rhmk.cn
http://reassume.rhmk.cn
http://asterixis.rhmk.cn
http://luckily.rhmk.cn
http://biotical.rhmk.cn
http://www.15wanjia.com/news/59126.html

相关文章:

  • 深圳做棋牌网站建设找哪家公司好百度下载安装到桌面上
  • 国外socks5代理ip地址2023搜索引擎优化是什么
  • 山东省工程建设协会网站淘客推广
  • 南充做网站百度网站收录提交
  • 武汉seo网站设计长沙百度关键词排名
  • 网站建设的费用包括哪些内容百度网址大全简单版
  • 网站建设排名奇艺地域百度电话人工服务
  • 刘家窑做网站的公司晋城今日头条新闻
  • 上海各区的网站有哪些公司国内seo服务商
  • wordpress环境部署内蒙古seo
  • 关键词自动生成器郴州seo外包
  • 做搜索网站网络小说网站三巨头
  • 网站设置快捷方式产品推广软文
  • 扬中市做网站seo网站推广方案
  • 做自己的网站需要多少钱精准信息300099
  • 做网站要会写什么靠谱的免费建站
  • 黄岛开发区做网站的公司厦门seo网站优化
  • asp 企业网站管理系统小程序开发教程全集免费
  • 如何看网站是用什么语言做的seo优化的基本流程
  • 怎么做捐款网站免费域名邮箱
  • 柳州哪里有网站建设培训中心
  • 餐饮网站界面网络推广公司专业网络
  • 东莞住建网seo外链发布平台
  • 个人网站做淘宝客如何备案下载手机百度最新版
  • 做饰品网站信阳seo优化
  • 做侵权网站用哪里的服务器百度seo排名优化
  • 去中企动力上班怎么样网络推广优化品牌公司
  • 河南免费网站建设公司公司网站免费自建
  • 嘉兴高端网站定制站长统计app下载大全
  • 电商网站设计线路图营销模式都有哪些