写在最前:移动端中导航的网花样结构无处无在,宽高怎么设置相适应?米素怎么居中对齐?差别场景怎么选择代码更高效?巧妙使用margin、padding等基础属性,小小技巧可以解决许多烦恼!
首页导航结构(无间距)
<div class="d509-4186-cc51-7922 g-grid"> <div class="4186-cc51-7922-f6e1 g-grid-item"> <div class="cc51-7922-f6e1-fbd7 g-grid-imgWrap"> <img class="58fd-a050-9b71-447c item-img" src="img/g1.png" /> </div> <p class="a050-9b71-447c-d51c g-grid-label">汽车票船票</p> </div> <!-- 以下九个子米素结构相同省略 --> </div>
.g-grid { text-align: center; overflow: hidden; background: #fff; } .g-grid-item { position: relative; float: left; width: 20%; padding: 10px 0; text-align: center; } .g-grid-imgWrap { display: inline-block; width: 30%; height: 0; padding-bottom: 30%; } .g-grid-imgWrap img { width: 100%; } .g-grid-label { font-size: 12px; color: #333; }
①、父米素g-grid通过overflow: hidden确立BFC,使得整体高度从1酿成自适应。通常可使用clearfix来消灭浮动的副作用
.clearfix:after{ display: block; clear: both; content: ""; visibility: hidden; height: 0; } .clearfix{ zoom:1; }
②、子米素g-grid-item通过float: left属性浮动起来,这也是该方式最主要的属性。
③、移动端对照常见的一个需求是高度凭据宽度举行自适应。这个时刻可以使用到padding-bottom。当width和padding-bottom相等时就实现了宽高相等(注重要将height置为0),闻一知十,种种比例下也可以设置。
width: 30%; height: 0; padding-bottom: 30%;
引申:vh和vw是css引入视口的观点来取代显示器的物理尺寸,它们作为单米的时刻也可实现该效果,虽然现在兼容性逐步变好,然则Android4.4之前不支持是硬伤。
vw:1vw即是视口宽度的1%。
vh:1vh即是视口高度的1%。
height:1vw; width:1vw;
首页导航结构(有间距)
页面结构与Float结构相同
.g-grid { margin-right: -2%; padding: 10px 10px 0; font-size: 0; background: #fff; } .g-grid-item { position: relative; display: inline-block; width: 31.33%; padding-bottom: 31.33%; margin-right: 2%; margin-bottom: 10px; } .g-grid-imgWrap { position: absolute; top: 0; left: 0; right: 0; bottom: 20px; } .g-grid-imgWrap img { width: 100%; height: 100%; } .g-grid-label { position: absolute; bottom: 0; width: 100%; height: 20px; line-height: 20px; font-size: 12px; color: #333; text-align: center; }
①、g-grid-item设置display:inline-block结构经常会使得米素米素间莫名其妙泛起清闲。可以在写代码时使得米素和米素牢牢相连,但不太利便我们编写代码,IDE花样化之后也会自动离开。此处建议设置父米素g-grid的font-size属性为0就可以去掉清闲。
②、g-grid-item这些子米素之间需要距离时用到margin-right(或者margin-left),经常要处置最后一行设置为margin-right(或者margin-left)为0。有以下解决方式:
楼上的float结构也可以使用该方式去设置间隙
③、宽高若干不仅仅可以通过设置值来决议,该例子内里使用以下代码实现了width:100%,高度为父级高度减去20px,凭据场景差别来决议写法。
position: absolute; top: 0; left: 0; right: 0; bottom: 20px;
④、float结构和display:inline-block结构的水平居中通常使用text-align: center;,子米素在父米素里水平居中要求子米素display不为block
网格结构(无间距)
<div class="9b71-447c-d51c-67b1 g-grid"> <div class="447c-d51c-67b1-f992 g-grid-item"> <img class="d51c-67b1-f992-f28e item-img" src="img/g1.png" /> <p class="67b1-f992-f28e-2f9c g-grid-label">汽车票船票</p> </div> <!-- 以下八个子米素结构相同省略 --> </div>
.g-grid { display: grid; grid-template-columns: repeat(3, 33.33%); grid-template-rows: repeat(3, 100px); background: #fff; } .g-grid-item { display: inline-grid; border-right: 1px solid #eee; border-top: 1px solid #eee; align-content: center justify-items: center; } .g-grid-item:nth-child(3n) { border-right: none; } .g-grid-item img { height: 30px; width: 30px; } .g-grid-label { font-size: 12px; color: #333; }
①、grid结构通过grid-template-columns和grid-template-rows来设置几列几行
②、g-grid-item通过设置align-content: center;来使得子米素都处于垂直居中,justify-items: center来使得子米素都处于水平居中
九宫格结构(有清闲)
页面结构与Grid结构相同请输入代码
.g-grid { display: flex; flex-wrap: wrap; } .g-grid-item { flex: 0 1 31.33%; margin: 0px 1% 10px; padding: 1.2rem; box-sizing: border-box; text-align: center; background: #eee; } .g-grid-item img { height: 30px; width: 30px; } .g-grid-label { font-size: 12px; color: #333; }
①、Flex结构通过flex-wrap: wrap;来举行换行,但当需要米素与米素之间存在间距时,不能使用justify-content: space-between;,削减一个米素会酿成下图:
以是该例子通过margin来设置间距。
②、.g-grid-item设置flex: 0 1 31.33%;意思是米素的原本巨细为父米素的31.33%,空间不足时该米素将缩小,存在剩余空间也不放大。
当该值设为flex: 1 1 31.33%;时,削减一个米素会酿成下图:
原文来自:https://segmentfault.com/a/1190000020047828
1.阿里云: 本站现在使用的是阿里云主机,平安/可靠/稳固。点击领取2000米代金券、领会最新阿里云产物的种种优惠流动点击进入
2.暗码分组链接形式(Cipher Block Chaining (CBC))Chm钓饵:挖矿木马喜欢将本身进程名命名为体系进程来利诱用户,除了部分挖矿进程直接运用xxxminer外,最常运用的进程名...
近日,电影《陈翔六点半之民间高手》持续热映。电影由陈翔导演、编剧,罗义担任制片人,蘑菇头、妹大爷、润土、毛台、陈翔、猪小明、王炸、球球、米线儿、冷檬、吴妈倾情出演。陈翔六点半团队凭借真实自然的演技与接...
31/44 Architects的James Jeffries 为他的家人设计了一个宽敞明亮的阿姆斯特丹联排别墅,面对着灰色的砖砌建筑,内部被大天窗照亮。与威廉·伯吉斯(William Burges)...
每日好文 黑客wifi怎么读取聊天记录 世界十大神秘组织与星际联盟(星际战甲神秘点播) 零电脑基础的怎么学黑客 黑色月季骇客(黑色珍珠棉厂家) 黑客是怎么入侵你的网站 微信号找个人信息(个人微信号大...
相信很多奶爸奶妈都会有遇到熊孩子乱涂鸦,把水彩笔涂到衣服上,衣服放洗衣机或者手洗都洗不掉的经历,现在小编教各位几种快捷去除水彩笔渍、油性笔渍的方法: 去除衣服上水彩笔渍的方法 1、衣服干的时候...
本文目录一览: 1、那些所谓的黑客是不是骗人的 2、哪个黑客论坛比较好 3、黑客论坛哪个最好最牛啊 4、比较好的黑客论坛 那些所谓的黑客是不是骗人的 都是骗人的,我被骗了,不要听他们甜言...