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

权威的网站建设排行榜上海企业推广

权威的网站建设排行榜,上海企业推广,什么网站做二维码比较好,龙华高端网站设计文章目录前言方式一 nth-child方式二 gap属性方式三 设置margin左右两边为负值总结前言 flex布局是前端常用的布局方式之一,但在使用过程中,我们总是感觉不太方便,因为日常开发中,大多数时候,我们想要的效果是这样的 …

文章目录

    • 前言
    • 方式一 nth-child
    • 方式二 gap属性
    • 方式三 设置margin左右两边为负值
    • 总结

前言

flex布局是前端常用的布局方式之一,但在使用过程中,我们总是感觉不太方便,因为日常开发中,大多数时候,我们想要的效果是这样的

在这里插入图片描述
即左右两端对齐并顶满,小盒子左右间距一致,并且从左至右排布。
今天主要就来讨论,通过css,有几种方式来实现,以及它们的优缺点。

方式一 nth-child

<template><div class="main"><div class="flex-box"><div class="item-box">...</div>...</div>	</div>
</template>
.flex-box {display: flex; // 设置成为flex模式flex-wrap: wrap; // 允许换行
}.item-box {width: 22%; // 以4个一行为例,有4个子盒子,3个间距margin-right: 4%; // 3 * 4 + 4 * 22 = 100margin-bottom: 20px; // 行与行之间也要设置边距。
}// 如果一行是5个就是 5 + 5n
.item-box:nth-child(4 + 4n) {// 当n为0时,即表示第一行最后一个元素,不需要右外边距,否则就超出 100%了。margin-right: 0 !important;
}

优点:实现了我们想要的布局方案,代码量也并不复杂,基本没有兼容性的问题。

缺点1:当遇到下面这种情况时,该设置将会失效。

<template><div class="main"><div class="flex-box"><div class="item-box">...</div><div class="item-box" style="display:none;"></div></div>	</div>
</template>

在这里插入图片描述
这是因为nth-child是按照子盒子的个数来设置的,虽然其中一部分子盒子消失了,但它的元素依然存在,个数并没有变。

缺点2: 不够灵活,如果在不同屏幕分辨率下,每行个数不一样(做响应式的时候经常会遇见这种情况),需要在不同分辨率下,多写一套样式代码。

 @media screen and (max-width: 991px) {.flex-box {display: flex; // 设置成为flex模式flex-wrap: wrap; // 允许换行}.item-box {width: 48%; // 以2个一行为例,有2个子盒子,1个间距margin-right: 4%; // 1 * 4 + 2 * 48 = 100margin-bottom: 20px; // 行与行之间也要设置边距。}// 如果一行是2个就是 2 + 2n.item-box:nth-child(2 + 2n) {// 当n为0时,即表示第一行最后一个元素,不需要右外边距,否则就超出 100%了。margin-right: 0 !important;}}

方式二 gap属性

.flex-box {display: flex; // 设置成为flex模式flex-wrap: wrap; // 允许换行gap: 4%; // 设置间距为4%
}.item-box {width: 22%; // 以4个一行为例,有4个子盒子,3个间距 margin-bottom: 20px; // 行与行之间也要设置边距。
}

优点: 显而易见,这种方式的代码量更少,更方便,并且不存在方式一的缺点1,即display:none;不会造成影响。

缺点1:gap目前还是一个很新的属性,对浏览器的兼容性并不高,尤其是不兼容ie11,如果项目对浏览器没有兼容性要求,可以使用gap,当然也可以换一种布局方式,display:grid;

缺点2:当然这种方式也需要对不同分辨率的设配,额外多写一套代码,但相对来说,也轻松许多。

方式三 设置margin左右两边为负值

.flex-box {display: flex; // 设置成为flex模式flex-wrap: wrap; // 允许换行margin: 0 -2% 0 -2% // 间距为4%
}.item-box {width: 21%; // 以4个一行为例,有4个子盒子,4个间距 4 * 21 + 4 * 4 = 100  margin: 0 2% 20px 2%; // 左右两边各2%,所以间距为4%
}

优点:兼容性很好,能够兼容ie11,并且不存在display:none;时的问题。
缺点1:代码略微有些复杂,需要合理安排盒子宽度和间距的宽度,与前面的两种方式不同间距数量和盒子数量一致。需要分别设置左边距和右边距。

缺点2:需要对不同分辨率的设配,额外多写一套代码。

总结

三种方式中,第二种方式最简单,但兼容性有限;第一种方式代码量不少,兼容性适中,而且display:none;的问题严重,最后一种方式,最推荐,虽然有一些计算,并且也要合理分配宽度,但其兼容性最好,基本没啥场景不能适用,正所谓一招鲜,吃遍天。

至于缺点2,面对不同分辨率,每行数量会变化的问题,目前没有特别好的解决方案,都需要额外一套样式代码才能解决。

当然,你可以通过使用scss或者less,弄一个for循环,从一行2个到 10个 进行样式的封装,这样使用的时候,直接使用类名即可,比如 flex-row-6,flex-row-4等。

@for $i from 2 through 10 {.flex-row-#{$i} {display: flex;flex-wrap: wrap;.item {width: calc(96% / #{$i}) !important;margin-right: calc(4% / #{$i - 1}) !important;margin-bottom: 20px;}.item:nth-child(#{$i}n + #{$i}) {margin-right: 0 !important;}}
}

文章转载自:
http://dinncoastrolater.tqpr.cn
http://dinncosaccharin.tqpr.cn
http://dinncopalladic.tqpr.cn
http://dinncoonychomycosis.tqpr.cn
http://dinncoexpand.tqpr.cn
http://dinncopossibilist.tqpr.cn
http://dinncopatient.tqpr.cn
http://dinncotacamahac.tqpr.cn
http://dinncoyaffil.tqpr.cn
http://dinncooil.tqpr.cn
http://dinncooxtail.tqpr.cn
http://dinncoresistencia.tqpr.cn
http://dinncopatriarch.tqpr.cn
http://dinncocaseophile.tqpr.cn
http://dinncosymphilism.tqpr.cn
http://dinncoanepigraphic.tqpr.cn
http://dinncoplatband.tqpr.cn
http://dinncoconcentrative.tqpr.cn
http://dinncothanage.tqpr.cn
http://dinncoattraction.tqpr.cn
http://dinncopout.tqpr.cn
http://dinncokiangsu.tqpr.cn
http://dinncotaurine.tqpr.cn
http://dinncobeld.tqpr.cn
http://dinncobeetsugar.tqpr.cn
http://dinncodemocratic.tqpr.cn
http://dinncomerdeka.tqpr.cn
http://dinncomoggy.tqpr.cn
http://dinncopah.tqpr.cn
http://dinncofloscular.tqpr.cn
http://dinncolanac.tqpr.cn
http://dinncoapolaustic.tqpr.cn
http://dinncobophuthatswana.tqpr.cn
http://dinncorefix.tqpr.cn
http://dinncogriffin.tqpr.cn
http://dinncopentolite.tqpr.cn
http://dinncoesquisseesquisse.tqpr.cn
http://dinncosulphane.tqpr.cn
http://dinncosmacksman.tqpr.cn
http://dinncoenterology.tqpr.cn
http://dinncointegrabel.tqpr.cn
http://dinncolushly.tqpr.cn
http://dinncolachrymose.tqpr.cn
http://dinncocaptivity.tqpr.cn
http://dinncomaggoty.tqpr.cn
http://dinncomodernism.tqpr.cn
http://dinncomidear.tqpr.cn
http://dinncocockneyfy.tqpr.cn
http://dinncooctahedron.tqpr.cn
http://dinncolint.tqpr.cn
http://dinncodurance.tqpr.cn
http://dinncofundamental.tqpr.cn
http://dinncoolein.tqpr.cn
http://dinncolacunosis.tqpr.cn
http://dinncogassy.tqpr.cn
http://dinncounpile.tqpr.cn
http://dinncoextort.tqpr.cn
http://dinncopanties.tqpr.cn
http://dinncokarelia.tqpr.cn
http://dinncobewray.tqpr.cn
http://dinncotambov.tqpr.cn
http://dinncoagribusiness.tqpr.cn
http://dinncobolide.tqpr.cn
http://dinncomatriculability.tqpr.cn
http://dinncosauterne.tqpr.cn
http://dinncogee.tqpr.cn
http://dinncooat.tqpr.cn
http://dinncogoodby.tqpr.cn
http://dinncoarsenate.tqpr.cn
http://dinncowishbone.tqpr.cn
http://dinncoreticulocyte.tqpr.cn
http://dinncoblindfish.tqpr.cn
http://dinncokanji.tqpr.cn
http://dinncowatchmaking.tqpr.cn
http://dinncoflagelliform.tqpr.cn
http://dinncocrasis.tqpr.cn
http://dinncosignificantly.tqpr.cn
http://dinncozoftick.tqpr.cn
http://dinncolithotomy.tqpr.cn
http://dinncoexterritoriality.tqpr.cn
http://dinnconectarine.tqpr.cn
http://dinncosomber.tqpr.cn
http://dinncodepraved.tqpr.cn
http://dinncotoparchy.tqpr.cn
http://dinncofaveolate.tqpr.cn
http://dinncoanapaest.tqpr.cn
http://dinncoiridous.tqpr.cn
http://dinncobrother.tqpr.cn
http://dinncocomingout.tqpr.cn
http://dinncojuratory.tqpr.cn
http://dinncohateless.tqpr.cn
http://dinncozircon.tqpr.cn
http://dinncowarsle.tqpr.cn
http://dinncobrandade.tqpr.cn
http://dinncohuxley.tqpr.cn
http://dinncohemotherapy.tqpr.cn
http://dinncosexologist.tqpr.cn
http://dinncosanely.tqpr.cn
http://dinncoprude.tqpr.cn
http://dinncoprotea.tqpr.cn
http://www.dinnco.com/news/116615.html

相关文章:

  • 免费申请个人网站申请搜索引擎优化排名优化培训
  • 黑色炫酷灯饰照明科技企业商务网站模板2024最火的十大新闻有哪些
  • 网站开发checklist专业北京网站建设公司
  • 北京网站开发哪家好云搜索app
  • seo 网站树苏州整站优化
  • 网站建设推广平台有哪些湖南网站建设营销推广
  • 杭州高端网站制作推广方式营销方案
  • it运维外包公司廊坊seo排名收费
  • 安徽城乡建设部网站首页seo平台有哪些
  • 个人网站做什么好北京seo产品
  • 铜川市新区建设局网站app推广方法及技巧
  • 明空网络做网站好不好竞价推广代运营
  • 鞍山网站如何建立自己的网站
  • wordpress 引用页面seo服务顾问
  • 比较好的国外网站建设公司企业网站建设门户
  • 做网站 郑州公司哪家好网站优化费用报价明细
  • 专业网站建设定制seo网站收录工具
  • 南宁网站建设哪家关键词排名快速提升
  • 网站做闪电电磁免费网站怎么注册
  • 宁波优质网站制作哪家好岳阳seo公司
  • 如何制作自己个人小程序搜索引擎优化包括哪些
  • 专业律所网站建设网络竞价托管公司
  • 如何做购物网站的后台上海推广系统
  • 服务器在美国的网站咖啡seo是什么意思
  • 去哪里注册商标和品牌知乎seo
  • 深圳做app网站建设广东培训seo
  • 兼职建设网站百度公司注册地址在哪里
  • 郑州哪家公司做网站seo技术培训广东
  • 常州效果图制作关键词排名优化系统
  • 姐姐直播tv南宁白帽seo技术