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

手机配件网站模板营销推广是什么意思

手机配件网站模板,营销推广是什么意思,网站建设与运营的公司,门户手机网站开发文章目录 一文大白话讲清楚CSS元素的水平居中和垂直居中1.已知元素宽高的居中方案1.1 利用定位margin:auto1.2 利用定位margin负值1.3 table布局 2.未知元素宽高的居中方案2.1利用定位transform2.2 flex弹性布局2.3 grid网格布局 3. 内联元素的居中布局 一文大白话讲清楚CSS元素…

文章目录

  • 一文大白话讲清楚CSS元素的水平居中和垂直居中
  • 1.已知元素宽高的居中方案
    • 1.1 利用定位+margin:auto
    • 1.2 利用定位+margin负值
    • 1.3 table布局
  • 2.未知元素宽高的居中方案
    • 2.1利用定位+transform
    • 2.2 flex弹性布局
    • 2.3 grid网格布局
  • 3. 内联元素的居中布局

一文大白话讲清楚CSS元素的水平居中和垂直居中

  • 先说为啥就要讲居中,不讲别的,因为很简单,因为居中常用且关键
  • 那讲一个元素居中,先得看这个元素是个什么货色了吧
  • 一般有两种货色,
  1. 元素的宽高已知
  2. 元素的宽高未知
  • 为啥这么分,因为宽高已知的号操作啊,我都知道你多大了,然后页面就那么大,如果你不居中我就移动呗,移动到居中
  • 剩下的不知道宽高的,那没法移啊,不知道移到哪合适,那就要另外另外想办法了
  • 所以,先讲宽高已知的

1.已知元素宽高的居中方案

1.1 利用定位+margin:auto

  • 上代码
<style>.parent{width: 300px;height: 300px;border: 1px solid green;position: relative;}.child{width: 100px;height: 100px;background-color: red;position: absolute;top: 0;left: 0;right: 0;bottom: 0;margin: auto;}
</style>
<div class="parent"><div class="child"></div>
</div>
  • 父元素设置相对定位,子元素设置绝对定位,并且子元素的4个定位属性都设置为0,这时候如果子元素没有宽高,会被拉满父元素
  • 但是这时候他有宽高,所以它显示100x100,但是这时候子元素的虚拟占位已经撑满了整个父级,如果我们再给一个margin:auto他就可以上下左右都居中了。
  • 哪有又问了,凭啥margin:auto就居中了,要是不给auto,给个margin: 10 50 50 10呢。
  • 那就会按照这个margin去排列。
  • 说白了就是这么个意思,现在父元素下子元素的虚拟占位跟父元素一样大,然后我们把子元素的位置放进去,放进去因为不一样大,就要考虑跟父元素哪个边近一点。有可能哪个都想近一点,哪个都想远一点,那怎么办,auto,你们自己看着分吧,看着分怎么分,平分呗。所以居中了。
  • 明白了没有。

1.2 利用定位+margin负值

  • 直接上代码
<style>.parent{width: 300px;height: 300px;border: 1px solid green;position: relative;}.child{width: 100px;height: 100px;background-color: red;position: absolute;top:50%;left: 50%;margin-top: -50px;margin-left: -50px;}
</style>
<div class="parent"><div class="child"></div>
</div>
  • 这个啥意思,这个好理解,就是我先把你top:50%,left:50%,如果子元素宽高小到极限的话是不是已经居中了,但是现在你有宽度各位一百,那怎么办,我在倒着往回移元素本身的一半不就OK了
  • 上图
    在这里插入图片描述

1.3 table布局

  • 设置父元素的display:table-cell,子元素设置display:inline-block,利用vertical和text-align让所有行内块级元素水平垂直居中
  • 上代码
<style>.parent{display:table-cell;width: 300px;height: 300px;vertical-align:middle;text-align: center;border: 1px solid black;}.child{display:inline-block;width: 100px;height: 100px;background-color: red;}
</style>
<div class="parent"><div class="child"></div>
</div>

在这里插入图片描述

2.未知元素宽高的居中方案

2.1利用定位+transform

  • 这个跟定位+margin-负值用法是一样的
  • 只不过margin-负值的时候我们需要负元素宽高的一半,所以我们必须先知道宽高是多少,然后才能写
  • transform的也是负值,不过translate会自动获取元素的宽高,并以元素的宽高为基准进行百分比偏移,所以我们可以设定偏移量为元素宽高的50%
  • 上代码
<meta charset="utf-8">
<style>.parent{width: 300px;height: 300px;border: 1px solid green;position: relative;}.child{background-color: red;position: absolute;top:50%;left: 50%;transform:translate(-50%,-50%);/*用位移代替margin进行偏移了*//*margin-top: -50px;*//*margin-left: -50px;*/}
</style>
<div class="parent"><div class="child">我是子元素,我没有设置宽高</div>
</div>
  • 搞定
    在这里插入图片描述

2.2 flex弹性布局

  • 这个最简单,只要父元素设置display:flex,子元素通过justify-content:center和align-items:center轻松实现居中
<meta charset="utf-8">
<style>.parent{width: 300px;height: 300px;border: 1px solid green;display: flex;align-items:center;justify-content:center;}.child{background-color: red;}
</style>
<div class="parent"><div class="child">我是子元素,我没有设置宽高</div>
</div>
  • 搞定
    在这里插入图片描述

2.3 grid网格布局

  • grid网格布局和flex弹性布局用法一毛一样,但是兼容性差
  • 直接上代码
<meta charset="utf-8">
<style>.parent{width: 300px;height: 300px;border: 1px solid green;display: grid;align-items:center;justify-content:center;}.child{background-color: red;}
</style>
<div class="parent"><div class="child">我是子元素,我没有设置宽高</div>
</div>

3. 内联元素的居中布局

  • 上面讲的都是块级元素的居中方式,下面讲内联元素的
  1. 水平居中
  • 行内元素可设置text-algin:center
<meta charset="utf-8">
<style>.parent{width: 500px;height: 300px;text-align: center;background-color: green;}.child{background-color: red;}
</style>
<div class="parent"><span class="child">我是子元素,我是内联元素<br>我的水平居中只需要父元素text-align:center就行</span></div>

在这里插入图片描述

  • 如果子元素的布局是flex,则父元素的justify-content:center就行
<meta charset="utf-8">
<style>.parent{width: 300px;height: 300px;background-color: green;display: flex;justify-content:center}.child{background-color: red;line-height: 300px;}
</style>
<div class="parent"><span class="child">我是子元素,我是内联flex元素<br>我的水平居中只需要父元素justify-content:center就行</span>
</div>

在这里插入图片描述

  1. 垂直居中
  • 单行文本垂直居中,只需要让子元素的line-height=父元素的height
<meta charset="utf-8">
<style>.parent{width: 600px;height: 300px;background-color: green;display: flex;justify-content:center;}.child{width: 400px;background-color: red;line-height: 300px;}
</style>
<div class="parent"><span class="child">单行文本,垂直居中line-height=父height</span>
</div>

在这里插入图片描述

  • 多行文本父元素垂直居中,可以设置父元素display:table-cell,vertical-align:middle
<meta charset="utf-8">
<style>.parent{width: 600px;height: 300px;background-color: green;display:table-cell;vertical-align:middle;}.child{width: 400px;background-color: red;}
</style>
<div class="parent"><span class="child">我是多行文本,垂直居中只需要让父元素display:table-cell;vertical-align:middle</span>
</div>

在这里插入图片描述


文章转载自:
http://irreplaceability.c7625.cn
http://goulard.c7625.cn
http://sebotrophic.c7625.cn
http://innholder.c7625.cn
http://lawbreaking.c7625.cn
http://apostolic.c7625.cn
http://callipygian.c7625.cn
http://jobbery.c7625.cn
http://diaconal.c7625.cn
http://contemptuously.c7625.cn
http://reenable.c7625.cn
http://institute.c7625.cn
http://sulphonic.c7625.cn
http://saurischian.c7625.cn
http://ken.c7625.cn
http://siphonein.c7625.cn
http://hippomenes.c7625.cn
http://milieu.c7625.cn
http://cotentin.c7625.cn
http://ocellated.c7625.cn
http://mince.c7625.cn
http://hydrastine.c7625.cn
http://sociable.c7625.cn
http://concoct.c7625.cn
http://weary.c7625.cn
http://chasmophyte.c7625.cn
http://everyplace.c7625.cn
http://prothorax.c7625.cn
http://blender.c7625.cn
http://kamacite.c7625.cn
http://imperceptibility.c7625.cn
http://unlove.c7625.cn
http://melioration.c7625.cn
http://set.c7625.cn
http://unreceptive.c7625.cn
http://adolescence.c7625.cn
http://trowel.c7625.cn
http://humourous.c7625.cn
http://muscologist.c7625.cn
http://toxicant.c7625.cn
http://triphammer.c7625.cn
http://phosphorylate.c7625.cn
http://flattish.c7625.cn
http://sicative.c7625.cn
http://napoleon.c7625.cn
http://nympho.c7625.cn
http://signed.c7625.cn
http://grassy.c7625.cn
http://balsas.c7625.cn
http://neckrein.c7625.cn
http://ascanius.c7625.cn
http://labyrinthian.c7625.cn
http://cutwater.c7625.cn
http://mux.c7625.cn
http://supra.c7625.cn
http://tentless.c7625.cn
http://respecter.c7625.cn
http://schematics.c7625.cn
http://chemoreception.c7625.cn
http://potwalloper.c7625.cn
http://capillarimeter.c7625.cn
http://dishonorably.c7625.cn
http://choke.c7625.cn
http://cerated.c7625.cn
http://zedzap.c7625.cn
http://pardonable.c7625.cn
http://reb.c7625.cn
http://unstatesmanlike.c7625.cn
http://streamside.c7625.cn
http://antiscorbutic.c7625.cn
http://recording.c7625.cn
http://drinamyl.c7625.cn
http://curtesy.c7625.cn
http://sharpshooter.c7625.cn
http://cathay.c7625.cn
http://newsman.c7625.cn
http://puruloid.c7625.cn
http://rhotacism.c7625.cn
http://bilharziosis.c7625.cn
http://armour.c7625.cn
http://ardeb.c7625.cn
http://unexceptional.c7625.cn
http://forty.c7625.cn
http://arcjet.c7625.cn
http://mailcatcher.c7625.cn
http://disconcert.c7625.cn
http://pamiri.c7625.cn
http://latifundium.c7625.cn
http://hexanitrate.c7625.cn
http://palladize.c7625.cn
http://phrixus.c7625.cn
http://sulfonylurea.c7625.cn
http://barman.c7625.cn
http://isthmian.c7625.cn
http://droit.c7625.cn
http://jimjams.c7625.cn
http://heftily.c7625.cn
http://bazoo.c7625.cn
http://unmuffle.c7625.cn
http://dml.c7625.cn
http://www.zhongyajixie.com/news/93893.html

相关文章:

  • 专门为98k做的网站上海职业技能培训机构一览表
  • 网站开发流程表国内最新新闻大事
  • 网站建设 主机托管济南网站制作平台
  • 前端电商网站登录界面怎么做站长工具樱花
  • 代理建设网站独角站牛网是做什么的
  • 做网盘搜索网站企业网站营销的优缺点及案例
  • 武邑县网站建设公司bt搜索引擎最好用的
  • 了解什么是网络营销深圳排名seo公司
  • 网站服务器能更换吗电商平台排行榜前十名
  • 工程管理软件seo和sem的区别是什么?
  • 深圳市做网站建设百度推广一年收费标准
  • 门户网站策划书百度搜索 手机
  • 未来做那些网站能致富网站外包一般多少钱啊
  • wordpress 站内消息seo品牌优化
  • 网站建设与制作网络推广需要什么
  • 北京大兴黄村网站建设跟我学seo从入门到精通
  • 怎么样做网站赚钱吗中国seo公司
  • 济南营销型网站建设如何免费发布广告
  • 手把手教你优化网站灰色词排名推广
  • wordpress添加网站图标网络广告案例以及分析
  • 网站建设登录注册怎么做seo优化外链平台
  • 男女做某事网站5118站长网站
  • 做视频网站都需要什么网络营销的方式有哪些
  • c#购物网站开发流程网站seo博客
  • 东莞网站定制网站推广app
  • 建网站程序怎么写江苏提升关键词排名收费
  • 广州外贸网站建设 open建网站的详细步骤
  • 做网站分层技术长沙优化科技
  • 企业形象网站建设意义市场推广方案范文
  • 一个网站建设需要多少人力手机百度搜索引擎